为什么网站没有与nginx重定向

问题描述 投票:0回答:1

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

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

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

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

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

方法1

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;
    }
    ....

}

保存后重启nginx

sudo service nginx restart
sudo systemctl restart nginx
nginx redirect http-status-code-301 vesta
1个回答
0
投票

最后,添加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;
    }
    .....
}
© www.soinside.com 2019 - 2024. All rights reserved.