您的位置:首页 > 运维架构 > Nginx

LNMP搭建7:Nginx域名跳转

2017-02-25 12:44 211 查看
编辑Nginx的虚拟主机配置文件
[root@cp1 vhosts]# vim test.conf
将替他域名永久跳转到主域名301
server
{
listen 80;
server_name www.test.com www.aaa.com www.bbb.com;
if($host != 'www.test.com')
{
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location /abc/ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
测试配置无误后重新加载配置文件:
[root@cp1 vhosts]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cp1 vhosts]# /etc/init.d/nginx reload
重新载入 Nginx: [确定]
测试:
[root@cp1 vhosts]# curl -x127.0.0.1:80 www.aaa.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 22 Feb 2017 17:01:46 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://www.test.com/ [root@cp1 vhosts]# curl -x127.0.0.1:80 www.bbb.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 22 Feb 2017 17:02:11 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://www.test.com/ 常见nginx的301和302配置参考帖子:http://ask.apelearn.com/question/4840
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  搭建 nginx LNMP