我正在尝试将域example.com重定向到另一个网站example.blogspot.com(它不在我的服务器中托管)。
我一直在使用htaccess
和cpanel
,因此很容易重定向。但是为什么重定向在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
最后,添加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;
}
.....
}