比如如下这个配置
[root@host-192-168-0-2 vhost]# vim test.conf server{ listen 80; server_name jenkins.centoscn.cn gitlab.centoscn.cn; index index.html index.htm index.php; root /data/wwwroot/jenkins.centoscn.cm;if ($host != 'jenkins.centoscn.cn' ) { rewrite ^/(.*)$ http://jenkins.centoscn.cn/$1 permanent; }location /admin/ { auth_basic "Auth"; auth_basic_user_file /usr/local/nginx/conf/htpasswd;}}
有jenkins.centoscn.cn和gitlab.centoscn.cn两个域名或者后面跟多个,我们访问gitlab.centoscn.cn域名时自动跳转到Jenkins.centoscn.cn
重新加载一下
[root@host-192-168-0-2 vhost]# /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@host-192-168-0-2 vhost]# /usr/local/nginx/sbin/nginx -s reload
curl页面测试
[root@host-192-168-0-2 vhost]# curl -x127.0.0.1:80 gitlab.centoscn.cn/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Fri, 22 Dec 2017 07:50:50 GMT Content-Type: text/htmlContent-Length: 185 Connection: keep-alive Location: http://jenkins.centoscn.cn/index.html
web测试
浏览区输入如下域名会自动跳转到jenkins.centoscn.cn上面
http://gitlab.centoscn.cn