阿里云CentOS 7.5 使用Nginx配置多个域名及转发


现有三个测试域名已经指向同一台服务器:

  1. www.testa.com,指向一个html静态页面
  2. www.testb.com,指向一个html静态页面
  3. 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配置文件:

  1. testa --> /home/website/testa
  2. 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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值