我使用nginx作为一个烧瓶应用程序的代理,以uwsgi作为中间件。 这是我testing应用程序的nginxconfiguration。
server { listen 80; server_name test.myapp.com www.test.myapp.com; charset utf-8; client_max_body_size 250M; location / { try_files $uri @testapp; }
location @testapp { include uwsgi_params; uwsgi_pass unix:/tmp/testapp_uwsgi.sock; } location /forecaster/components/ { alias /opt/test/client/app/components/; }
}
我很确定,虽然nginx实际上并没有提供静态文件,即使我注释掉了location块,文件也得到了某些东西。 我在nginx日志中看到了200个,在uWsgi日志中看到了200个。 你怎么知道哪一个服务于静态文件? 我想烧瓶应用程序可以为他们服务呢?
/ opt / test / client / app / components /肯定存在,并且对其他人可读。 有没有办法强制uwsgi不处理这些请求?
你确实需要一个location 。 但是,这不是为什么nginx不提供你的静态文件。
问题是你忘记了在你的server块中指定一个root指令。 所以nginx使用它的编译默认,这是依赖于系统,几乎肯定不是你的web应用程序所在的位置。 因此,包括静态文件在内的所有请求都会上传到uWSGI。
要解决这个问题,请设置一个指向您的应用程序的静态资源的root指令。
server { root /srv/www/testapp;
或者,如果在子目录中只有静态文件,则可以使用location和alias来指定,如uWSGI文档中所示 。
location /static { alias /srv/www/testapp/static; }