【问题标题】:Nginx site configuration disabling 301 rewrite for another siteNginx 站点配置为另一个站点禁用 301 重写
【发布时间】:2013-08-29 06:36:19
【问题描述】:

我目前在 nginx 中启用了两个站点配置,我们分别称它们为 old-site.examplenew-site.example。没有其他活动的站点配置。

old-site.example 应该 301 重定向到 new-site.example。只要old-site.example 配置单独,这目前就可以正常工作。添加new-site.example配置文件后,不再重定向。

oldsite.conf:

server {
        listen 80;
        server_name *.old-site.example;
        rewrite_log on;
        location / {
                return 301 http://www.new-site.example$request_uri;
        }

}

newsite.conf:

server {
    listen       80;
    server_name  www.new-site.example;

charset utf-8;

    location / {
        #forward to application server
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080;
    }
}

其他配置细节:

  • JBoss AS7 作为运行在 Nginx 1.5.1 后面的应用服务器

【问题讨论】:

    标签: redirect nginx http-status-code-301


    【解决方案1】:

    这是一个与 DNS 相关的错误,对不起大家。

    背景:客户端的 ISP 设法“智能重定向”域,而不是使用 DNS。他们基本上在他们的服务器上抓取了新站点并通过旧域返回它。我无语了。

    如果您遇到过这样的问题,请在再次猜测您的配置之前检查 DNS 解析。

    【讨论】:

    • 只是添加另一个注释,因为我使用了 firefox,所以我注意到一些相关的东西,firefox 有时会缓存 301 响应,所以即使你更改设置 firefox 也不知道新设置,所以你应该清除缓存并重试,有时这就是问题
    猜你喜欢
    • 2019-07-03
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多