【问题标题】:why site is not redirecting with nginx为什么网站不使用 nginx 重定向
【发布时间】:2019-08-22 19:22:03
【问题描述】:

我正在尝试将域 example.com 重定向到另一个网站 example.blogspot.com(未托管在我的服务器中)。

我一直在使用htaccesscpanel,所以很容易重定向。但是为什么重定向在 nginx 中不起作用。

nginx/1.15.10和最新vesta control panel的版本中,以下方式看不到效果,

仍然显示由vesta控制面板生成的默认页面(index.html)。我应该更改 public_html 吗?还是重启服务器?

我用以下代码编辑了nginx.conf

方法一

http{
    server{
        listen          80;
        server_name     example.com www.example.com;
        return          301 https://example.blogspot.com$request_uri;
    }
    .....
}

方法2

http{
    server{
        listen [::]:80;
        listen          80;
        server_name     example.com www.example.com;
        return          301 https://example.blogspot.com$request_uri;
    }
    .....
}

方法3

http{
    server { 
        server_name .example.com;
        return 301 $scheme://example.blogspot.com;
    }
    ....

}

保存后重启ngix

sudo service nginx restart
sudo systemctl restart nginx

【问题讨论】:

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


    【解决方案1】:

    最后,添加Server Ip address 和监听端口重定向域

    http{
        server{
            listen          my.server.ip.address:80;
            server_name     example.com www.example.com;
            return          301 https://example.blogspot.com$request_uri;
        }
        .....
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多