2016-11-15 3 views
0

Amazon EC2에서 내 장고 프로젝트를 호스팅하는 데 문제가 발생했습니다. (자바 스크립트 콘솔에서 발췌) 브라우저에서 내 페이지를로드하려고 할 때 사이트를 호스팅 Gunicorn와 Nginx에 사용 , 나는 오류를 다음 얻을 :HTTP 504 게이트웨이 Django (Nginx + Gunicorn)로 정적 파일을 제공 할 때 시간 만료

내가 Nginx에 내 정적 파일을 찾는 몇 가지 문제를 가지고 있다고 생각
Failed to load resource: the server responded with a status of 504 (Gateway Time-out): https://example.com/favicon.ico 

, 하지만 왜 그런지 모르겠습니다. 아무것도 표시되지 않습니다 /var/log/nginx/error.log

server { 
    listen 443 default; 
    client_max_body_size 100M; 
    server_name www.example.com; 

    keepalive_timeout 5; 

    ssl on; 
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; 

    # the domain name it will serve for 
    charset  utf-8; 

    # path for static files 
    root /opt/app/staticfiles; 

    location /static { 
     root /opt/app/staticfiles; 
    } 

    location/{ 
     # checks for static file, if not found proxy to app 
     try_files $uri @proxy_to_app; 
    } 

    location @proxy_to_app { 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 

     proxy_pass http://app_server; 
    } 

} 

/var/log/nginx/access.log 고양이 : 여기 내 Nginx에의 설정입니다.

HTTP 코드 504의 경우 일반적으로 긴 요청이 걸리고 결국 시간 초과되는 문제가 있지만 사이트를로드하려고하기 때문에 내 프로젝트에 어떻게 적용되는지 잘 모르겠습니다.

이 문제를 디버깅하는 방법을 모르는 경우 도움이 될 것입니다.

답변

0

이 당신을 도울 수 있습니다 : 다음과 같이 내가 무슨 짓을

내가 /etc/nginx/site-enabled/default 파일을 편집한다 :

server { 
     #nginx server configuration 
     listen 80 default_server; 
#  listen [::] default_server ipv6only=on; 
     listen [::]:80 default_server ipv6only=on; 

     root /usr/share/nginx/html; 
     index index.html index.htm; 

     # Make site accessible from http://localhost/ 
#  server_name localhost; 
     # provide whole path of static files you got after running `python manage.py collectstatics` 
     location /static{ 
       alias /home/ubuntu/folder1/folder2/webpage/static; 
     } 

     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
       proxy_pass http://0.0.0.0:8134;#Provide your django server's link 
       # Uncomment to enable naxsi on this location 
       # include /etc/nginx/naxsi.rules 
     } 
} 

을 : - 당신이 python manage.py collectstatics을 수행했는지 확인하십시오. nginx.conf 파일에서 아무런 변경을하지 마십시오.