LNMP下的Nginx如果想将域名tpxhm.com 301重定向到www.tpxhm.com,同时www.tpxhm.com已经添加上,可以按如下步骤修改 使用命令编辑器vi、nano或winscp图形管理软件编辑对应的虚拟主机,一般虚拟主机配置文件位于:/usr/local/nginx/conf/vhost/域名.conf ,如添加的域名是www.tpxhm.com则配置文件
tpxhm.com 301跳转到www.tpxhm.com示例配置如下:
省略www.tpxhm.com虚拟主机server配置
server {
listen 80;
server_name tpxhm.com;
return 301 http://www.tpxhm.com$request_uri;
}如果是想让http强制跳转到https,把里面的http换成https就行。
http站点301跳转到https站点示例配置如下:
server {
listen 443 ssl;
server_name www.tpxhm.com;
省略其他配置
}server {
listen 80;
server_name tpxhm.com;
return 301 $request_uri;
}