我正在尝试让 nginx 与 gunicorn 一起工作。我有一个/project/static/
静态文件所在的目录。/project/livestatic/
使用显示的配置将这些文件收集到一个目录settings.py
中:
STATIC_ROOT = '/project/livestatic'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/project/static',
)
我正在使用以下 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 直接不提供文件。我怎么错了?