Nginx
Nginx 不提供靜態文件
可能重複:
我按照本指南在 Ubuntu 11.10 上部署 Django + Nginx。Django 執行良好,但不提供任何靜態文件。
這是我的 settings.py 的摘錄:
STATIC_ROOT = '' STATIC_URL = '/static/' ADMIN_MEDIA_PREFIX = DOMAIN_URL + '/static/admin/' STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static'), )
從 nginx.conf
server { listen 80; server_name localhost; # site_media - folder in uri for static files location /static/ { autoindex on; alias /project/app/static; } location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|p$ access_log off; # po co mi logi obrazków :) expires 30d; } location / { # host and port to fastcgi server fastcgi_pass 127.0.0.1:8080; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param QUERY_STRING $query_string; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_pass_header Authorization; fastcgi_intercept_errors off; }
我在這裡做什麼?
此外,這是我的 nginx 日誌
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$ 2012/04/17 13:48:24 [error] 15598#0: *3 open() "/etc/nginx/html/static/css/rese$ 2012/04/17 13:48:24 [error] 15598#0: *4 open() "/etc/nginx/html/static/images/l$ 2012/04/17 13:48:24 [error] 15598#0: *5 open() "/etc/nginx/html/static/js/scrip$ 2012/04/17 13:48:24 [error] 15598#0: *6 open() "/etc/nginx/html/static/js/jquer$ 2012/04/17 13:48:24 [error] 15598#0: *7 open() "/etc/nginx/html/static/style.cs$ 2012/04/17 13:48:24 [error] 15598#0: *8 open() "/etc/nginx/html/static/js/jquer$ 2012/04/17 13:48:24 [error] 15598#0: *5 open() "/etc/nginx/html/static/images/i$ 2012/04/17 13:48:24 [error] 15598#0: *7 open() "/etc/nginx/html/static/images/i$ 2012/04/17 13:48:24 [error] 15598#0: *8 open() "/etc/nginx/html/static/images/i$ 2012/04/17 13:48:24 [error] 15598#0: *6 open() "/etc/nginx/html/static/images/s$ 2012/04/17 13:48:24 [error] 15598#0: *3 open() "/etc/nginx/html/static/images/s$ 2012/04/17 13:48:24 [error] 15598#0: *4 open() "/etc/nginx/html/static/images/s$ 2012/04/17 14:07:33 [error] 16231#0: *1 FastCGI sent in stderr: "WSGIServer: mi$ WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$ 2012/04/17 14:07:33 [error] 16231#0: *3 open() "/etc/nginx/html/static/css/rese$ 2012/04/17 14:07:33 [error] 16231#0: *4 open() "/etc/nginx/html/static/style.cs$ 2012/04/17 14:07:33 [error] 16231#0: *5 open() "/etc/nginx/html/static/js/jquer$ 2012/04/17 14:07:33 [error] 16231#0: *6 open() "/etc/nginx/html/static/js/scrip$ 2012/04/17 14:07:33 [error] 16231#0: *7 open() "/etc/nginx/html/static/js/jquer$ 2012/04/17 14:07:34 [error] 16231#0: *7 open() "/etc/nginx/html/static/images/l$ 2012/04/17 14:07:34 [error] 16231#0: *6 open() "/etc/nginx/html/static/images/i$ 2012/04/17 14:07:34 [error] 16231#0: *4 open() "/etc/nginx/html/static/images/i$ 2012/04/17 14:07:34 [error] 16231#0: *5 open() "/etc/nginx/html/static/images/i$ 2012/04/17 14:07:34 [error] 16231#0: *3 open() "/etc/nginx/html/static/images/s$ 2012/04/17 14:07:34 [error] 16231#0: *8 open() "/etc/nginx/html/static/images/s$ 2012/04/17 14:07:34 [error] 16231#0: *5 open() "/etc/nginx/html/static/images/s$ 2012/04/17 14:07:35 [error] 16231#0: *5 open() "/etc/nginx/html/static/images/f$ 2012/04/17 14:10:30 [error] 16231#0: *9 FastCGI sent in stderr: "WSGIServer: mi$ WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$ 2012/04/17 14:11:57 [error] 16471#0: *1 FastCGI sent in stderr: "WSGIServer: mi$ WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$
我相信
alias /project/app/static;
需要一個斜杠,所以它應該是:alias /project/app/static/;