我尝试了很多不同的东西,但我发现的所有解决方案都没有帮助。
我将我的公司网站放在了ubuntu16.04上的一个数字海洋站点上,方法是遵循数字海洋航向 (它以前工作得很好),但它只提供一些静态文件。
以下是这些图片的链接。
<h3>Here is the image that doesn't load</h3>
<img src="http://206.189.161.104/static/images/frac_stack_1.jpg" alt="Image that doesn't load">
<h3>Here is the image that does load in the same folder</h3>
<img src="http://206.189.161.104/static/images/coil_pic.jpg" alt="Image that doesn't load" style="width:200px;height:200px;>
下面是我的nginx配置:
server {
listen 80;
server_name 206.189.161.104;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
root /home/dmckim/myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/dmckim/myproject/myproject.sock;
}
}
我试着删除静态中的尾随斜杠(如上面所示)。我还尝试将root更改为别名,并将静态文件夹添加到路径中,但结果是相同的。
下面是我的settings.py文件中的代码:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
'/home/dmckim/myproject/static/',
'/home/dmckim/myproject/static/images/',
)
我也尝试过在收集静态之前清除收集器,并且我总是在之后运行这些命令,并确保我的浏览器缓存被清除。
sudo systemctl restart gunicorn
sudo nginx -t && sudo systemctl restart nginx
我对这些文件的权限是-rw-rw-r--
,用于加载的图像和不加载的图像。我还尝试了很多方法来更改权限(我并不真正理解它们,但它们是在其他帖子中提出的)。我甚至训斥了服务器,并从零开始,以确保我没有破坏任何权限。
我没有发现nginx进程日志或访问日志有什么问题,但是错误日志显示了以下内容:
2018/05/31 13:04:19 [error] 11481#11481: *22 open()
"/home/dmckim/myproject/static/images/frac_stack_1.jpg" failed (2: No such
file or directory), client: 12.184.4.50, server: 206.189.161.104, request:
"GET /static/images/frac_stack_1.jpg HTTP/1.1", host: "206.189.161.104",
referrer: "http://206.189.161.104/frac-stacks/"
火奴鲁鲁的日志显示404的图像不会加载。
这里是www数据组uid=33(www-data) gid=33(www-data) groups=33(www-data)
。
这是我的小组uid=1000(dmckim) gid=1000(dmckim) groups=1000(dmckim),27(sudo)
发布于 2018-05-31 06:14:27
文件名区分大小写。您的图像名为"1.JPG“,而不是"1.jpg”。
<h3>Here is the image that loads</h3>
<img src="http://206.189.161.104/static/images/frac_stack_1.JPG" alt="Image that doesn't load" style="width:200px;height:200px;">
<h3>Here is the other image that does load in the same folder</h3>
<img src="http://206.189.161.104/static/images/coil_pic.jpg" alt="Image that doesn't load" style="width:200px;height:200px;>
请注意,您的结果在本地运行时可能会有所不同。Windows不区分大小写,Linux是区分大小写的。请参阅这个问题的细节
https://stackoverflow.com/questions/50626210
复制