【发布时间】:2014-11-16 19:23:08
【问题描述】:
我有一个 Django 项目并尝试使用 nginx 和 uwsgi 部署它(从现在开始一周)。 我可以访问服务器,但它不显示图片和 css。 nginx 提供静态文件(例如 localhost:8000/static/images/image.png 有效)但在 localhost:8001/ 上什么也没有(此页面应显示 image.png)。
这是我的 nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
#server unix:///home/serveur/www/gems/GEMS/gems.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 192.168.0.119; # substitute your machine's IP address or FQ
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/serveur/www/gems/GEMS/media; # your Django project's media files - amend as required
}
location /static {
alias /home/serveur/www/gems/GEMS/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/serveur/www/gems/uwsgi_params; # the uwsgi_params file you installed
}
}
settings.py:
TEMPLATE_DIRS = ('/home/serveur/www/gems/GEMS/templates'),
STATIC_URL = '/static/' #'/home/serveur/www/gems/GEMS/static/'
STATIC_ROOT = "/home/serveur/www/gems/GEMS/static/" #os.path.join(BASE_DIR, "static/")
MEDIA_ROOT = '/home/serveur/www/gems/GEMS/static/media'
STATICFILES_DIR = ('/home/serveur/www/gems/GEMS/static')
import django.contrib.auth
django.contrib.auth.LOGIN_URL = '/'
wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "GEMS.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我通过以下方式启动 uwsgi:
uwsgi --http :8001 --wsgi-file GEMS/wsgi.py --chdir /home/serveur/www/gems/GEMS --virtualenv /home/serveur/www/gems --chmod-socket=666
有人有想法吗?
谢谢
【问题讨论】:
-
你跑了 manage.py collectstatic?
-
是的,我做到了,但还是不行
-
你能从 nginx 错误日志中为静态 url 发布一行吗?
-
2014/11/16 19:06:53 [错误] 4437#0: *11 open() "/home/server/www/gems/GEMS/static" 失败(13:权限被拒绝),客户端:192.168.0.24,服务器:192.168.0.119,请求:“GET /static HTTP/1.1”,主机:“192.168.0.119:8000” 但是我更改了权限,因为我可以访问。奇怪的是,当我连接到端口 8001 时,gems.access.log 中没有出现任何内容
标签: python django nginx static uwsgi