配置 yum
源
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
安装 Nginx
sudo yum install -y nginx
启动 Nginx
并设置开机自动运行
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
配置根据域名进行代理
vi /etc/nginx/conf.d/xxx.conf
# 使用 80 端口,根据域名不同使用不同的接口代理
server {
listen 80;
server_name *.xxx.com;
if ($http_host ~* "^(.*?).xxx.com$") {
set $domain $1;
}
location / {
if ($domain ~* "aaa") { #域名中有aaa,转发到8080端口
proxy_pass http://0.0.0.0:8080;
}
}
location / {
if ($domain ~* "bbb") { #域名中有bbb,转发到8090端口
proxy_pass http://0.0.0.0:8090;
}
}
}
重启
nginx -s reload
或者
systemctl stop nginx.service
systemctl start nginx.service
systemctl status nginx.service