一、 选择主域名 -> 设置 -> 配置文件,如下图所示。
二、修改“配件文件”代码,这里以主域名“abc.com”为例,要给二级域名“a.xxx.com”和“b.xxx.com”做301分别跳转到“网址1.com”和“网址2.com”,即 a.xxx.com 跳到 网址1.com b.xxx.com 跳到 网址2.com。
配置文件代码如下:
server
{
listen 80;
server_name xxx.com www.xxx.com;
index index.html index.php index.htm default.php default.htm default.html;
root /www/wwwroot/xxx;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#301-START
if ($host ~ '^xxx.com'){
return 301 http://www.xxx.com$request_uri;
}
#301-END
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
error_page 404 /404.html;
error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-54.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/xxx.com.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log off;
}
access_log /www/wwwlogs/xxx.com.log;
error_log /www/wwwlogs/xxx.com.error.log;
}
#BINDING-a.xxx.com-START
server
{
listen 80;
server_name a.xxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/xxx/a;
#301-START
#301-END
include enable-php-54.conf;
include /www/server/panel/vhost/rewrite/xxx.com.conf;
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log off;
}
access_log /www/wwwlogs/xxx.com.log;
error_log /www/wwwlogs/xxx.com.error.log;
}
#BINDING-a.xxx.com-END
#BINDING-b.xxx.com-START
server
{
listen 80;
server_name b.xxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/xxx/b;
#301-START
#301-END
include enable-php-54.conf;
include /www/server/panel/vhost/rewrite/xxx.com.conf;
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log off;
}
access_log /www/wwwlogs/xxx.com.log;
error_log /www/wwwlogs/xxx.com.error.log;
}
#BINDING-b.xxx.com-END
找到 #301-START 的配置项操作保存后,清理下本地浏览器缓存后,就尝试下输入原域名吧,看看有没有成功实现301重定向。