nginx反向代理网站遇到的一些问题
使用nginx反向代理百度之类的网站和反向代理自己发布的服务设置上有点差别
使用include 配置文件方式,
首先在 nginx.conf文件的 http 中 加入,
include /etc/nginx/proxy34.conf;
proxy34.conf 文件内容如下:
## Basic reverse proxy server ## ## backend for 16.32 ## upstream uicps { # server 192.168.16.32:59002 weight=1; server www.163.com; } ## Start 16.32 ## server { listen 9000; server_name localhost; # access_log logs/proxy34.access.log main; # error_log logs/proxy34.error.log; root html; index index.html index.htm index.php; ## send request back to 16.32 ## location / { proxy_pass http://uicps; #Proxy Settings proxy_redirect off; proxy_set_header Host www.163.com; # $host;不能使用$host变量 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
另一种情况Nginx有反向代理用户的真实IP地址:
从nginx模块中取$remote_addr值为上一级代理的IP地址,而非真实客户端的IP地址。为了获取真实客户端IP地址,可以使用nginx自带的realip模块。此模块可将真实客户端IP地址设置进HTTP请求头中,以便后端的web服务器获取。
set_real_ip_from 192.168.1.209; 其中192.168.1.209是代理服务器地址
反向代理的nginx配置
location / { #root /usr/share/nginx/html/minor/public; #try_files $uri $uri/ /index.php?$query_string; proxy_pass http://192.168.1.219; proxy_set_header Host $host; set_real_ip_from 192.168.1.209; 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 REMOTE_ADDR $remote_addr; index index.php index.html index.htm; }
转载自:https://blog.csdn.net/chenyulancn/article/details/70841298
https://blog.csdn.net/chuoban7047/article/details/100764831

浙公网安备 33010602011771号