listen 80;

    server_name www.test1.com www.aaa1.com www.bbb1.com;

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

{

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

}

/usr/local/nginx/sbin/nginx -t

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


测试

 curl -x127.0.0.1:80  www.aaa1.com/sdsdsssss -I

HTTP/1.1 301 Moved Permanently

Server: nginx/1.8.0

Date: Sat, 02 Jan 2016 06:52:38 GMT

Content-Type: text/html

Content-Length: 184

Connection: keep-alive

Location: http://www.test1.com/sdsdsssss


测试

 curl -x127.0.0.1:80  www.test1.com/sdsdsssss -I

HTTP/1.1 404 Not Found

Server: nginx/1.8.0

Date: Sat, 02 Jan 2016 06:53:03 GMT

Content-Type: text/html

Content-Length: 168

Connection: keep-alive