Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pzzrudlf/c3db463fec14217a4d93f137c804c3fd to your computer and use it in GitHub Desktop.
Save pzzrudlf/c3db463fec14217a4d93f137c804c3fd to your computer and use it in GitHub Desktop.
内网有三台服务器A/B/C, 由于申请的固定IP只有一个IP, 80端口只能给一个机器使用, 所以需要使用反向代理做域名转发去实现
这里我将A作为反向代理服务器(其实我也没搞明白为啥这么叫), 在A服务器上安装好nginx
一般在 /usr/local/nginx/conf/nginx.conf 里面 http模块里面 include /usr/local/nginx/conf/vhost/*.conf , 这样直接在vhost 建立对应域名文件配置 server模块即可
server
{
listen 80;
server_name oa.test.com;
location / {
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.1.2:8082;#这里填写内网B服务器, 以及对应的端口就可以转发过去了
}
access_log /data/wwwlogs/oa.test.com.log;
}
  
如果想做负载均衡可以这么配置
upstream oa_server {
server 10.0.1.2:8082;
server 10.0.1.3:8082;
}
server
{
listen 80;
server_name oa.test.com;
location / {
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://oa_server;#这里oa_server和upstream模块oa_server是一样的
}
access_log /data/wwwlogs/oa.test.com.log;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment