在 ubuntu 服务器中访问图像时,带有 Uwsgi 的 Nginx 抛出 404 未找到

Nginx with Uwsgi throws 404 not found when accessing image in the ubuntu server

我创建了一个 Flask 应用程序并使用 Nginx 和 uwsgi 将其部署在远程 ubuntu 服务器中。但是我无法访问应用程序文件夹中的图像。图像存储在 /myproject/static/images/ 文件夹中。

这是服务器块

server {
    listen 80;
    server_name _;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/root/myproject_sock/myproject.sock;
    }
}

如何通过图像 URL 访问保存在 /myproject/static/images/ 文件夹中的图像,即 HTTP://myip/myproject/static/images/first_image.jpg ?

感谢@RichardSmith (https://whosebug.com/users/4862445/richard-smith),问题已解决。 如果您遇到同样的问题,您需要在 /etc/nginx/sites-available/myproject 中编辑您的服务器块(我的项目可以是您之前为项目命名的任何内容)。

您需要添加 locationroot 指令。例如:location /DIR_NAME/myproject/static/images/ { root /; }。在 DIR_NAME 中,您需要放置 myproject 文件夹的父目录。

关注:http://nginx.org/en/docs/beginners_guide.html