0

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:

  • OS System: CentOS 6.9_64
  • Nginx version 1.10.2

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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Did you find an answer for this? I am facing the same issue currently.
This lead me to the answer for my issue: stackoverflow.com/questions/66870877/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.