LNMP配置——Nginx配置 ——域名重定向
一、配置
#vi /usr/local/nginx/conf/vhost/test.com.conf
写入:
server
{
listen 80;
server_name test.com test1.com test2.com;
//是server_name后面可以跟多个域名
index index.html index.htm index.php;
root /data/nginx/test.com;
if ($host != 'test.com' ){
rewrite ^(.*)$ http://test.com/$1 permanent;
//permanent为永久重定向,相当于httpd的R=301
}
}
#/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 successfu

二、检验测试
#curl -x127.0.0.1:80 test1.com/123.txt -I
状态码301

检验成功
                    
                
                
            
        
浙公网安备 33010602011771号