Nginx location 为HTTP流量配置Nginx的反向代理出现403

Nginx location 为HTTP流量配置Nginx的反向代理出现403,nginx-location,nginx-reverse-proxy,nginx-config,Nginx Location,Nginx Reverse Proxy,Nginx Config,我试图在centos 6.9_64环境中使用Nginx作为反向代理,在该环境中,客户端连接到我的服务器() Nginx将所有请求转发到其他后端服务器。通信正在端口80上工作 但是,一旦设置了proxy_set_头XXXXX,访问时将显示403。 /var/log/nginx/error.log中没有相关的错误信息 问题出在哪里 第403页禁止 您没有访问此服务器上URL的权限 注意: 操作系统:CentOS 6.9_64 Nginx版本1.10.2 配置: /etc/nginx/nginx.

我试图在centos 6.9_64环境中使用Nginx作为反向代理,在该环境中,客户端连接到我的服务器()

Nginx将所有请求转发到其他后端服务器。通信正在端口80上工作

但是,一旦设置了proxy_set_头XXXXX,访问时将显示403。 /var/log/nginx/error.log中没有相关的错误信息

问题出在哪里

第403页禁止

您没有访问此服务器上URL的权限

注意:

  • 操作系统:CentOS 6.9_64
  • Nginx版本1.10.2
配置:

/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;
   }
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 {
 }
}
/etc/nginx/conf.d/default.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;
   }
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 {
 }
}

原始问题是由“proxy\u set\u header Host$Host”引起的, 代理集头X-Real-IP和代理集头X-Forwarded-For没有问题

但还是不明白为什么


你找到答案了吗?我目前面临着同样的问题。这让我找到了问题的答案: