我正在尝试将Nginx用作客户端连接到我的服务器(http://www.51ti.vip)的centos 6.9_64环境中的反向代理。
Nginx将所有请求转发到其他后端服务器。通信正在端口80上进行。
但是,一旦设置了proxy_set_header XXXXX,在访问时它将显示403。 /var/log/nginx/error.log中没有相关的错误信息。
出什么问题了?
禁止页面403
您无权访问此服务器上的URL。
注意:
配置:
/etc/nginx/nginx.conf如下:
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.conf如下:
server {
listen 80 default_server;
server_name 47.75.249.199 "";
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://sq.otherserver.com;
#Proxy Settings
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;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
答案 0 :(得分:0)
原始问题是由“ proxy_set_header主机$ host”引起的, proxy_set_header X-Real-IP和proxy_set_header X-Forwarded-For都没有问题。
但还是不明白为什么?
Nginx: when to use proxy_set_header Host $host vs $proxy_host