现有三个测试域名已经指向同一台服务器:
- www.testa.com,指向一个html静态页面
- www.testb.com,指向一个html静态页面
- gitlab.code.com, 代码管理服务,gitlab服务端口83
1.环境
CentOS 7.5已经安装好nginx和gitlab服务,其中nginx默认端口80, gitlab端口配置成83, 并且端口83已经加入阿里云安全组里面!
2.新建目录vhost存放conf文件
[root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# mkdir /etc/nginx/vhost
[root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# cd /etc/nginx/vhost
3.新建3个conf文件
# www.testa.com
[root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# vi vhost_testa.conf
server {
listen 80;
server_name www.testa.com testa.com;
root /home/website/testa;
location / {
index index.html index.htm index.php;
}
}
# www.testb.com
[root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# vi vhost_testb.conf
server {
listen 80;
server_name www.testb.com testb.com;
root /home/website/testb;
location / {
index index.html index.htm index.php;
}
}
# gitlab.code.com
[root@iZ8vb2zp3hb2pskrfnjcrbZ nginx]# vi vhost_gitlab.conf
server {
listen 80;
server_name gitlab.code.com;
root /usr/share/nginx/html;
index index.html index.htm index.php; #default index
location / {
proxy_pass http://localhost:83; #此处在作重定向,也作很多处理
}
}
4.静态页面html配置路径
根据conf配置文件:
- testa --> /home/website/testa
- testb --> /home/website/testb
5.修改nginx配置默认加载3个conf文件
[root@iZ8vb2zp3hb2pskrfnjcrbZ vhost]# vi /etc/nginx/nginx.conf
...
http {
...
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
# include /etc/nginx/conf.d/*.conf;
# 加上路径
include /etc/nginx/vhost/*.conf;
...
}
6.重新加载nginx配置
[root@iZ8vb2zp3hb2pskrfnjcrbZ vhost]# nginx -s reload
[root@iZ8vb2zp3hb2pskrfnjcrbZ vhost]# service nginx restart