我对此还是个新手,但我正在尝试将我使用Django构建的网站部署到使用nginx/gunicorn的DigitalOcean。
我的nginx文件如下所示:
server {
listen 80;
server_name xxx.xxx.xxx.xx;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static/ {
alias ~/dev/WebPortfolio/static/;
}
}我的settings.py文件看起来是这样的:
STATIC_ROOT = '~/dev/WebPortfolio/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = ()每次运行python managy.py collect static时,错误看起来是这样的:
You have requested to collect static files at the destination
location as specified in your settings:
/root/dev/WebPortfolio/~/dev/WebPortfolio/static查看我看到的nginx错误日志(去掉重复的内容):
2015/10/08 15:12:42 [error] 23072#0: *19 open() "/usr/share/nginx/~/dev/WebPortfolio/static/http:/cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.e asing.min.js" failed (2: No such file or directory), client: xxxxxxxxxxxxxx, server: xxxxxxxxxxxxxx, request: "GET /static/http%3A//cdnjs.cloudflare.com/aj ax/libs/jquery-easing/1.3/jquery.easing.min.js HTTP/1.1", host: "XXXXXXXX.com", referrer: "http://XXXXXXXX.com/"
2015/10/08 15:14:28 [error] 23072#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: xxxxxxxx, server: 104.236.174.46, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "xxxxxxxx.com"1)我不完全确定为什么静态文件的目标是'/root/dev/WebPortfolio/~/dev/WebPortfolio/static‘
发布于 2015-10-09 03:47:48
因为您在路径中使用了'~‘。这是一个shell问题,而不是一般的路径问题,除非您明确告诉Python,否则它不知道如何处理它。在Django设置和nginx中都使用完整的绝对路径。
https://stackoverflow.com/questions/33024252
复制相似问题