Nginx在网站启用时丢失了一个网站的静态图片 [英] Nginx lost my static images for one site in sites-enabled

查看:178
本文介绍了Nginx在网站启用时丢失了一个网站的静态图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站启用中有两个网站 nginx

1) project - 这本质上是顶级域 - mysite.com

1) project - this is essentially the top level domain - mysite.com

server {
    listen 80;
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /static {
        alias  /home/www/flask-deploy/project/static/;
    }
}

2) code> - 这是一个博客,可通过以下访问:mysite.com:8080

2) blog - this is for a blog, that is accessible via: mysite.com:8080

server {
    listen 8080;

    location blog/ {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /static {
        alias  /home/www/flask-deploy/blog/static/;
    }
}

Nginx已接受这两种配置,

Nginx has accepted both configurations, but when I visit 1 i get all of the text, but no css, or images.

如果我访问

If I visit 2 i get everything working fine.

>谢谢

推荐答案

对于别名指令正常工作, 位置中的URI和别名指令中的URI都应以 / 或两者都不在 / 中结束。该算法似乎用一个字符串替换另一个。

For the alias directive to work correctly, the URI in the location and the URI in the alias directive should both end in / or neither end in /. The algorithm seems to substitute one string for the other.

所以你应该写:

location /static {
    alias  /home/www/flask-deploy/project/static;
}

然而,当别名的最后一个元素与位置匹配时,首选 root 指令(请参阅 this ):

However, when the last element(s) of the alias match the location, the root directive is preferred (see this):

location /static {
    root  /home/www/flask-deploy/project;
}

您的位置博客/ 看起来不正确,前缀位置应始终以 / 开头。

Your location blog/ looks incorrect, prefix locations should always begin with a /.

这篇关于Nginx在网站启用时丢失了一个网站的静态图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆