[英]Unable to access static files with NGINX, gunicorn and Django
我有一個通過ajenti與NGINX和Django一起運行的項目。 不幸的是,我無法遍歷靜態目錄。 我已設置索引並嘗試手動遍歷它,但是我被卡在同一目錄中。
NGINX配置:
server {
listen *:80 default_server;
server_name testsite.com;
access_log /var/log/nginx/testsite.access.log;
error_log /var/log/nginx/testsite.error.log;
root /var/www/servers/testsite.com/testsite;
index index.html index.htm index.php;
location / {
proxy_pass http://unix:/var/run/ajenti-v-gunicorn-testsite-python-wsgi-0.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ /static/ {
alias /var/www/servers/testsite.com/testsite/public/static/;
autoindex on;
}
}
金槍魚的過程:
root 2829 0.9 2.4 57896 12312 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
www-data 2842 2.1 5.0 83572 25928 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
www-data 2849 1.9 4.7 82056 24208 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
www-data 2858 1.8 4.7 82064 24212 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
NGINX流程:
ps -ef | grep nginx
root 29364 1 0 11:40 ? 00:00:00 nginx: master process /usr/sbin/nginx
www-data 29365 29364 0 11:40 ? 00:00:00 nginx: worker process
root 29378 26678 0 11:43 pts/0 00:00:00 grep nginx
目錄權限:
ls -ls
total 52
36 -rwxrwxrwx 1 www-data www-data 36864 Apr 10 10:58 db.sqlite3
4 -rwxrwxrwx 1 www-data www-data 250 Apr 10 10:58 manage.py
4 drwxrwxrwx 3 www-data www-data 4096 Apr 10 10:59 public
4 drwxrwxrwx 2 www-data www-data 4096 Apr 10 11:29 testsite
4 -rwxrwxrwx 1 www-data www-data 169 Apr 10 11:08 testsite.wsgi
該圖顯示了無法遍歷目錄。
嘗試將其包含在urls.py
文件中:
admin_media_path = os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
urlpatterns = patterns('',
url(r'^static/admin/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': admin_media_path,
}),
)
這應該可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.