我有一个启用了我的网站的nginx服务器,它正在侦听443并将流量转发到使用uWSGI的django应用服务器。我可以进入管理页面并登录但不提供静态文件。我跑了python3 manage.py collectstatic
。在使用letsencrypt
添加SSL之前,一切正常。在nginx访问日志中获取此信息:
"GET /static/admin/css/base.css HTTP/1.0" 404
这是我的反向代理nginx站点配置:
upstream staging_app_server {
server 52.52.52.52;
}
server {
listen 80;
server_name staging.site.com;
rewrite ^/(.*) https://staging.site.com/$1 permanent;
}
server {
listen 443;
server_name staging.site.com;
include snippets/ssl-staging.site.com.conf;
include snippets/ssl-params.conf;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
access_log /var/log/nginx/staging.access.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://staging_app_server;
proxy_redirect http://staging_app_server https://staging_app_server;
}
location ~ /.well-known {
allow all;
}
}
app server nginx config:
server {
listen 80;
server_name staging.site.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /home/ubuntu/api/staticfiles;
}
location /media/ {
alias /home/ubuntu/api/media;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/api.sock;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Host $server_name;
uwsgi_param X-Forwarded-Proto $scheme;
}
}
我错过了什么?
答案 0 :(得分:1)
您的alias
陈述错误。 location
的值和alias
的值都应该以{{1}}结尾,或者都不会以/
结尾。
另外,使用/
root
值以alias
值结尾的位置。有关详细信息,请参阅this document。
例如:
location
答案 1 :(得分:0)
这有效:
location /static {
autoindex on;
alias /home/ubuntu/api/staticfiles;
}
感谢@ richard-smith指出我正确的方向!