参考:
server{
listen 80;
listen [::]:80;
server_name test1.abc.com;
# proxy_set_header REMOTE_ADDR $remote_addr;
location / {
proxy_pass http://localhost:8665/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-HOST $host:$server_port; # 关键需要在此处添加端口号变量,或者直接使用端口号8070
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header REMOTE_ADDR $remote_addr;
# add_header REMOTE_ADDR $remote_addr;
#获取客户端IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
set_real_ip_from 172.17.0.3/24; #这里的IP是代理服务器的IP,也可以是IP段。意思是把该IP请求过来的x_forwarded_for设为remote_addr
real_ip_header X-Forwarded-For;
}
}
server{
listen 80;
listen [::]:80;
server_name test2.abc.com;
# proxy_set_header REMOTE_ADDR $remote_addr;
location / {
proxy_pass http://localhost:8666/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-HOST $host:$server_port; # 关键需要在此处添加端口号变量,或者直接使用端口号8070
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header REMOTE_ADDR $remote_addr;
# add_header REMOTE_ADDR $remote_addr;
#获取客户端IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
set_real_ip_from 172.17.0.3/24; #这里的IP是代理服务器的IP,也可以是IP段。意思是把该IP请求过来的x_forwarded_for设为remote_addr
real_ip_header X-Forwarded-For;
}
}
如上可以使用域名test1.abc.com监听8665端口,test2.abc.com 监听8666端口
如果有有受某些限制,也可以将监听端口80 更改为其他端口,比如8000
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/1605.html