アプリケーションがそれらを提供している場合は、アプリケーションからnginxリバースプロキシ静的ファイルを取得しようとしています。そうでない場合は、それら自体を提供しています。現在、私はこの構成を持っています:
upstream app_server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
}
server {
listen 8080;
server_name example.com;
access_log /var/log/nginx.access.log;
error_log /var/log/nginx.error.log;
keepalive_timeout 5;
location /static {
try_files $uri @proxy_to_app;
alias /path/to/__static;
sendfile off;
}
location / {
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;
}
}
これは、ファイルが に存在しない場合に機能し/path/to/__static
ます。要求をアプリケーション サーバーに送信します。ただし、ファイルが にも存在する場合/path/to/__static
、nginx はファイル自体を提供します。
行の反転try_files
( try_files @proxy_to_app $uri
) はどちらの場合も失敗します。クライアントが をリクエストする/static/css/test.css
と、アプリケーションは のリクエストを受信し、アプリケーションが 404 を返しても、リクエスト/css/test.css
を試行していないように見えます。/path/to/__static
完全な構成が含まれるように更新されました。