【发布时间】:2019-01-30 21:37:42
【问题描述】:
栈是:Ubuntu // Supervisor // Nginx Gunicorn Django 1.11
静态文件夹:/home/sitebiz/sitebiz/static/
Nginx 配置:/etc/nginx/sites-enabled/site.biz
server {
listen 80;
listen [::]:80;
access_log off;
server_name site.biz;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
#listen 80 ssl;
server_name site.biz;
ssl_certificate /etc/letsencrypt/live/site.biz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.biz/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
#listen 80;
gzip on;
access_log /var/log/nginx-access.log;
error_log /var/log/nginx-error.log;
location /static {
root /home/sitebiz/sitebiz;
internal;
}
location /track {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8899;
break;
}
}
location /income {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8899;
break;
}
}
location / {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8000;
break;
}
}
}
我尝试将 /home/sitebiz/sitebiz/static/ 目录及其所有内容所有权更改为 sitebiz 用户和 www-data ,但没有任何帮助。
甚至 Django 本身也不能提供静态文件,我不知道为什么。
来自 django 设置:
SITE_ROOT = os.path.abspath(os.path.dirname(name))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
提前谢谢你。
【问题讨论】:
-
root /sitebiz/sitebiz;这不会导致/home/ -
对不起,我不知道,为什么它在这里被破坏了。该块是 location /static/ { root /home/sitebiz/sitebiz;内部的; }
-
nginx错误日志中有条目吗?另外,nginxworker 用户名是否对/home/sitebiz/sitebiz/static/上面的所有目录具有读取权限? -
location /static {} 删除斜线
-
collectstatic工作了吗?禁止 403 错误。您可能需要chown要将静态文件收集到的目录,收集它们,然后chown将其返回。此外,如果这确实是问题,Fabric 对这些东西很有帮助:fabfile.org
标签: django nginx ubuntu-16.04 gunicorn nginx-config