2017-03-07 1 views
0

gunicorn -w 1 -b 0.0.0.0:8000 flaskapp:app 아래에 nginx config가있는 플라스크 앱이 있습니다. 그러나 nginx가 실제로 정적 파일을 제공하고 있는지 여부를 어떻게 알 수 있습니까? alias /home/pi/Public/flaskapp/static/;.../static-testing/;으로 변경하고 자리 표시자인 style.css을 넣으려고했지만 이전처럼 페이지가로드되는 것 같습니다.Nginx가 Flask 대신 정적 파일을 제공하는지 확인하십시오.

server { 
    listen 5000; 
    server_name _; 
    location/{ 
     proxy_pass http://127.0.0.0.1:8000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 
    location /static { 
     alias /home/pi/Public/flaskapp/static/; 
    } 
} 

나는 뭔가 분명하지 않습니까? 플라스크의 루트에서 뭔가를 지정해야합니까?

+0

규칙이 있으므로 서비스가 제공됩니다. 규칙을 제거하면 Flask가 규칙을 처리합니다 (비효율적으로). 나머지는 아마 브라우저 캐싱에 의존합니다. – davidism

+0

하지만 그럴 수있는 방법은 없을까요? –

+0

Gunicorn 로그를보십시오. 정적 자산을 다루고 있습니까? 그렇다면 Nginx는 그렇지 않습니다. – davidism

답변

0

http://nginx.org/en/docs/http/ngx_http_log_module.html 그래서 나는 마지막으로 제대로 nginx를 구성했습니다. 내가 루트를 추가하고 정적의 하드 경로를 제거, 또한 명확하게 정적 및 CSS는 nginx에서로드되는 것을 보여주는 로그 파일을 추가! 나는 또한 청취 포트를 80 (suprise)로 변경했다.

server { 
    listen 80; 

    server_name myapp.com; 
    root /home/pi/Public/myapp; 

    access_log /home/pi/Public/myapp/logs/nginx-access.log; 
    error_log /home/pi/Public/myapp/logs/nginx-error.log; 

    location/{ 
     proxy_pass http://127.0.0.1:8000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 

    location /static/ { } 

    location /uploads/ { } 
} 
0

nginx 위치 블록에 맞춤 헤더를 추가하고 정적 파일에 맞춤 헤더가 설정되어 있는지 확인할 수 있습니다.

+1

어떻게 할 수 있습니까? 나는 새로운 nginx를 사용하고 있습니다. –

0

/static/location에 언급 된 빈 경로를 사용하여 테스트 할 수 있습니다.

server { 
    listen 5000; 
    server_name _; 

    location /static/ { 

    } 

    location/{ 
     proxy_pass http://127.0.0.0.1:8000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 

}

이 404 오류를 줄 것이다 파일은 Nginx에 의해 제공되는 경우, 따라서 당신은 확인할 수 있습니다.

+0

여전히 정적 폴더에 파일을로드합니다. 결론 : 설치가 제대로 작동하지 않습니까? –

+1

'/'블록 위에'/ static' 블록을 놓고 시도해 볼 수 있습니까? –

0

가장 쉬운 방법은 일부 업스트림 변수를 액세스 로그에 기록하는 것입니다.

http://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables

당신은 HTTP 블록

upstream backend { 
    server 127.0.0.0.1:8000; 
} 

그런 다음 http://backend에 proxy_pass 변경에의 nginx의 conf에이를 추가해야합니다;

이제 서버 블록에

log_format upstream '$upstream_bytes_received $upstream_response_time'; 
access_log /var/log/nginx-upstream upstream; 

를 추가하고 nginx를 다시 시작합니다. nginx가 업스트림을 요청하지 않으면 '-'가 표시됩니다.

은 문서 : & http://nginx.org/en/docs/http/ngx_http_upstream_module.html

관련 문제