Colin Chen
Colin Chen

Reputation: 404

The reverse proxy that configured Nginx for HTTP traffic appears 403

I'm trying to use Nginx as a reverse proxy in and centos 6.9_64 environment where clients connects to my server (http://www.51ti.vip).

Nginx will forward all requests to other backend server. The communication is working on port 80.

However, once proxy_set_header XXXXX is set, it will appear 403 when accessed. There is no relevant error information in /var/log/nginx/error.log.

Where's the problem?

Page 403 Forbidden

You don't have permission to access the URL on this server.

Note:

Config:

/etc/nginx/nginx.conf as follows:

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 as follows:

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 {
 }
}

Upvotes: 0

Views: 3541

Answers (1)

Colin Chen
Colin Chen

Reputation: 404

The original problem was caused by "proxy_set_header Host $host", there's no problem whith proxy_set_header X-Real-IP and proxy_set_header X-Forwarded-For.

But still don't understand why?

Nginx: when to use proxy_set_header Host $host vs $proxy_host

Module ngx_http_proxy_module

Upvotes: 3

Related Questions