使用Django,Nginx和Gunicorn提供静态内容时遇到问题。我可以从我的/ media /文件夹以及html提供媒体文件(图像),但是对/ static /文件夹的静态请求产生了500个错误。
我运行了collectstatic来收集/ opt / myapp / myapp / myapp / static /
中的所有静态这是我的Nginx配置:
server {
listen 80;
server_name <ip_address>;
location = /favicon.ico { access_log off; log_not_found off; }
location = /static/ {
alias /opt/myapp/myapp/myapp/static/;
}
location = /media/ {
alias /opt/myapp/myapp/myapp/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/opt/myapp/myapp/myapp/myapp.sock;
}
}
Django urls.py:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('core.urls')),
url(r'^accounts/', include('allauth.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Django settings.py:
STATICFILES_DIRS = [
'/opt/myapp/myapp/myapp/core/static',
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'static')
来自Nginx access.log的示例(error.log中没有错误):
"GET /static/markup/css/index.css HTTP/1.1" 500 63893 "http://104.131.44.215/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
答案 0 :(得分:0)
你的settings.py看起来像什么?
编辑:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)