nginx域名重定向

1、编辑配置文件

vim /usr/local/nginx/conf/vhosts/test.conf

2、修改以下内容

 server_name www.test.com 

server_name www.test.com www.aaa.com www.bbb.com;

    if ($host != 'www.test.com')

    {

        rewrite ^/(.*)$ http://www.test.com/$1 permanent;

    }

3、重新加载配置文件

/usr/local/nginx/sbin/nginx -s reload

4、使用curl测试访问结果

curl -x127.0.0.1:80 www.bbb.com/1111111 -I

HTTP/1.1 301 Moved Permanently

Server: nginx/1.6.3

Date: Mon, 30 May 2016 06:48:14 GMT

Content-Type: text/html

Content-Length: 184

Connection: keep-alive

Location: http://www.test.com/1111111


你可能感兴趣的:(local,配置文件,permanent)