nginx反向代理实例配置
- 我们有一个主站是.NET的,是由几个小站组成的,现在我们需要再挂一个网站。
需要在windows机器上做反向代理,但是主站不在我们这里,修改起来比较麻烦。
之前的小站都是这样去反向代理的。
为了以后加小站不再麻烦别人,我们打算加一台nginx 做反向代理。
配置大概如下
server {
listen 80;
server_name www.xxx.com;
root /home;
index index.html index.htm index.php;
#主站
location / {
proxy_pass http://www.xxxx.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#a站目录
location ~ ^/(search|app|game|qp|dpscpi|news|zt)/.*$ {
proxy_pass http://soft.xxx.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
b站目录
location ~ ^/(gfapi|games|soft|zti|ssou|xp|sitemapv1).*$ {
proxy_pass http://app.xxxx.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log logs/www.xp002.com-access.log main;
}
#m站
server {
listen 80;
server_name m.xxx.com;
root /home;
index index.html index.htm index.php;
location / {
proxy_pass http://m.xxxx.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/(search|app|game|qp|dpscpi|news|zt)/.*$ {
proxy_pass http://m.xxx.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/(gfapi|games|soft|zti|ssou|xp|sitemapv1).*$ {
proxy_pass http://app.xxx.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log logs/www.xp002.com-access.log main;
}
Comment here is closed