Above an article to build a personal blog site, for example , the current domain name test.blog.com, add a domain name to point to the site www.blog.com
nginx configure multiple domain names:
Edit nginx virtual host configuration file:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
In the new domain name server_name key www.blog.com:
Verify the configuration and reload:
[root@linux ~]# nginx -t && nginx -s reload
Then you can access the site through the new domain www.blog.com:
nginx configure the domain name to redirect / Jump:
Edit nginx virtual host configuration file:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
Add the following:
if ( $host = test.blog.com )
{
rewrite /(.*) http://www.blog.com/$1 permanent;
}
Verify the configuration and reload:
[root@linux ~]# nginx -t && nginx -s reload
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
test:
[root@linux ~]# curl -x127.0.0.1:80 -I test.blog.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.1
Date: Sun, 13 Oct 2019 15:24:43 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://www.blog.com/
#http status code 301, Location: http://www.blog.com/, requests for test.blog.com has been successfully jump to www.blog.com, for search engines, test.blog.com be considered to be the old domain, and priority access to the new domain name www.blog.com
Permanent Redirect: permanent http status code: 301 (redirect domain use, transfer domain name weights)
Temporary Redirect: redirect http status code: 302 (Jump to use non-domain name, such as file Jump)
Edit nginx virtual host configuration file:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
nginx add files Jump:
rewrite /1.txt /2.txt redirect;
Verify the configuration and reload:
[root@linux ~]# nginx -t && nginx -s reload
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
test:
[root@linux ~]# curl -x127.0.0.1:80 -I www.blog.com/1.txt
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.16.1
Date: Sun, 13 Oct 2019 15:45:17 GMT
Content-Type: text/html
Content-Length: 145
Location: http://www.blog.com/2.txt
Connection: keep-alive
#http status code: 302, Location: http://www.blog.com/2.txt, file successfully jump