我正在尝试让nginx与gunicorn一起工作。我有一个目录
我将使用以下nginx配置:
在开发服务器(忽略nginx)下,这个配置可以正常工作,并且我可以通过在格式中链接到静态文件
/project/static/
,其中存放静态文件。这些文件被收集到一个目录/project/livestatic/
中,使用如下所示的settings.py
配置:STATIC_ROOT = '/project/livestatic'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/project/static',
)
我将使用以下nginx配置:
我正在使用以下nginx配置:
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
sendfile on;
upstream app_server {
server 127.0.0.1 fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name domain.org;
keepalive_timeout 5;
# path for static files
location /static/ {
autoindex on;
root /var/www/startupsearch_live/livestatic/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8888;
}
}
}
在开发服务器(忽略nginx)下,这个配置可以正常工作,并且我可以通过在格式中链接到静态文件
/static/file.extension
来提供静态文件。然而,一旦nginx/gunicorn参与进来,这就不起作用了,尝试访问domain.org/static/
会出现django 404页面,表明nginx根本没有提供文件。我做错了什么?