堆栈是: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')
先谢谢您。
答案 0 :(得分:0)