2017-11-16 1 views
0

저는 Mac에서 Angular 2 앱을 개발했으며 Nginx를 웹 검색기로 사용하여 로컬로 실행했습니다. 이 문제를 AWS EC2 인스턴스에 배포 할 때 문제가 있습니다. Linux Red Hat 7 인스턴스입니다.Nginx 404 또는 기본 페이지

나는 Nginx를 설치했고, 내 맥에서 server_name 값과 root를 변경하면서 작업 설정을 복사했지만 기본 nginx 페이지 나 404 오류를 얻는다.

/var/www/dist에 앱을 설치하고 해당 경로와 dist에있는 파일에 대해 chmod 755 권한을 부여했습니다. 아래는 내 config (server_name에 대한 꺾쇠 괄호는 실제 구성에 없는데, 나는이 게시물의 인스턴스 이름을 숨기고 있음을 참고하십시오)입니다.

myhost/index.html 또는 myhost/someapppath의 모든 시도는 모두 404를 반환합니다. myhost/을 사용하면 기본 nginx 페이지가 반환됩니다. 나는 심지어 html 디렉토리를 만들고 그곳에 파일을 올려서 테스트를 해보려고했지만 그걸 가져 가지도 않았다. 나는 각각의 설정 후에도 nginx를 재시작했지만 여전히 동일하게 작동한다.

아이디어가 있으십니까? UPDATE


user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; server { listen 80; server_name <hiding instance for this post>.ap-southeast-2.compute.amazonaws.com; root /var/www/dist; #charset koi8-r; #access_log logs/host.access.log main; location/{ index index.html index.htm; try_files $uri $uri$args $uri/index.html /index.html =404; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } #include /etc/nginx/conf.d/*.conf; } 

지금은 다음을 참조 오류 로그를보고 다시 설정 땜질 및 후 :

2017/11/16 17:12:14 [crit] 23126#23126: *2 stat() "/var/www/dist/index.html" failed (13: Permission denied)

이 더 의미가 있습니다. 나는 sudo chown nginx: var/sudo chown -R nginx: /var/www을 nginx 사용자를 위해 돌렸고 nginx를 재시작했지만 나는 여전히 허가를 얻지 못했다. 사용 권한을 올바르게 설정하고 있습니까?

+0

도와 드리겠습니다. 인덱스를/dist에 넣었습니까? 또한 서버 이름은 사용자가 요청할 URL이어야합니다. – Colton

+0

@colton index.html은/dist 폴더에 있고 server_name은 사이트에 액세스하는 데 사용하는 공용 DNS 이름입니다. 이상하게도 모든 것이 지역적으로 작동합니다. – rossco

답변

0

매우 까다로운 문제가 해결되었습니다. 이 게시물의 @jsina의 의견을 사용하여 해결 : https://stackoverflow.com/a/36389001/2313746.

효과적으로 mv/home의 디렉토리가 사용 권한의 컨텍스트를 업데이트하지 않습니다.