【发布时间】:2019-08-22 19:22:03
【问题描述】:
我正在尝试将域 example.com 重定向到另一个网站 example.blogspot.com(未托管在我的服务器中)。
我一直在使用htaccess 和cpanel,所以很容易重定向。但是为什么重定向在 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