【发布时间】:2020-09-18 00:13:14
【问题描述】:
您好,感谢您抽出宝贵时间阅读此帮助请求。
我正在安装一个名为 Netbox 的 Web 应用程序,它是基于 Django 构建的。一个基本的 Gunicorn 在 rather simplie configuration 中使用 NGINX 作为前端。
我遇到的问题是 Web 应用程序报告它无法加载任何静态文件,我可以验证这些请求是否收到 404。
我已验证我可以在 NGINX 路径 /opt/netbox/netbox/static 中引用的 /static/ 路径中查看正确的文件,并且权限设置也正确。
由于这是一个 Django 网络应用程序,我使用内置测试网络服务器执行了一个简单的测试,并且所有静态文件都正确呈现;这几乎可以肯定是 Gunicorn 和我的 NGINX 配置之间的问题。
nginx.conf
server {
listen 443 ssl;
# CHANGE THIS TO YOUR SERVER'S NAME
server_name netbox.example.com;
ssl_certificate /etc/ssl/certs/netbox.crt;
ssl_certificate_key /etc/ssl/private/netbox.key;
client_max_body_size 25m;
location /static/ {
alias /opt/netbox/netbox/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
# Redirect HTTP traffic to HTTPS
listen 80;
server_name _;
return 301 https://$host$request_uri;
}
gunicorn.py
bind = '127.0.0.1:8001'
workers = 5
threads = 3
timeout = 120
max_requests = 5000
max_requests_jitter = 500
error message when browsing http://localhost:8001/
我在以下设置中收到了相同的结果:
- Ubuntu 18.04 (Azure)
- Ubuntu 19.10(本地虚拟机)
- Ubuntu 20.04(本地虚拟机)
- Centos 8.1 (Azure)
- 使用 Apache 替代设置方法时出现相同错误
如果有任何想法可以验证权限或检查日志等内容,我将不胜感激。
【问题讨论】: