1. 程式人生 > >nginx反向代理 本地 兩臺web負載均衡 使用域名代理

nginx反向代理 本地 兩臺web負載均衡 使用域名代理

環境:

本地外網ip:123.58.251.166




1、配置index.html網頁

[[email protected]-10-1-1-161 conf.d]# cat /web/sing/index.html 
<h1>www.test1.com</h1>
[[email protected]-10-1-1-161 conf.d]# cat /root/html/index.html 
<h1>www.test2.com</h1>




2、配置conf.d目錄下配置檔案

[[email protected]-10-1-1-161
conf.d]# pwd /etc/nginx/conf.d [[email protected]-10-1-1-161 conf.d]# ls test1.conf test2.conf test3.conf [[email protected]-10-1-1-161 conf.d]# cat test1.conf server { listen 8083; server_name 127.0.0.1:8083; location / { root /web/sing/; index index.html index.htm; } } [[email protected]-10-1-1
-161 conf.d]# cat test2.conf server { listen 8086; server_name 127.0.0.1:8086; location / { root /root/html/; index index.html index.htm; } } [[email protected]-10-1-1-161 conf.d]# cat test3.conf upstream abc.com { server 127.0.0.1:8083 fail_timeout=20s; server 127.0.0.1:8086 fail_timeout=20s; #ip_hash; 開啟後就會訪問到一臺上 } server { listen
80; server_name oa.test.com; location / { #反向代理的地址 proxy_pass http://abc.com; } } 3、配置hosts [[email protected]-10-1-1-161 conf.d]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 123.58.251.166 oa.test.com [[email protected]-10-1-1-161 conf.d]# nginx -s reload 4、開始訪問 注意:要從百度訪問必須註冊備案域名 [[email protected]-10-1-1-161 ~]# curl http://oa.test.com <h1>www.test1.com</h1> [[email protected]-10-1-1-161 ~]# curl http://oa.test.com <h1>www.test2.com</h1>