# Nginx 域名反向代理配置
# 安裝nginx
yum install nginx -y
# 修改配置文件
進入配置文件目錄 cd /etc/nginx/conf.d
新建配置文件以.conf結尾 vim test.conf
輸入一下內容:
server {
listen 80;
server_name a.domain.com;
access_log /var/node/log/host.access.log main;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://192.168.2.2:7789;
# 支持websocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
##
proxy_redirect off;
}
}
server_name a.domain.com # 配置二級域名
proxy_pass http://42.159.191.244:7789 # 配置指向web服務
重啓 service nginx restart
訪問 http://a.domain.com 便可訪問到 http://192.168.2.2:7789 服務
若是配置多個代理 即 新建配置文件 test1.conf、test2.conf(必須在/etc/nginx/conf.d 目錄下創建)
server {
listen 80;
server_name b.domain.com;
access_log /var/node/log/host.access.log main;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://192.168.88.2:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
輸入配置內容 更改 server_name 與 proxy_pass 便可。node