This is my first time using nginx and I'm finding this situation quite puzzling. My website is hosted at web.example.com
and in order to reach the backend, requests are routed though nginx as a reverse proxy. After processing through nginx, the URL changes to the URL of the nginx server (proxy.example.com
) instead of being the URL of the website.
The flow looks something like this:
web.example.com -> nginx (proxy.example.com) -> backend (service.example.com)
When I log the request in the backend service, I can see that the x-forwarded-host is set to proxy.example.com
. Is this correct or should it be set to web.example.com
here?
The nginx.conf file is:
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
server { # simple reverse-proxy
listen 80;
server_name proxy.example.com;
location /site {
proxy_set_header Host $http_host;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-host $host;
proxy_set_header x-forwarded-server $host;
proxy_set_header x-real-ip $remote_addr;
proxy_pass_request_headers on;
proxy_pass http://service.example.com$request_uri;
}
}
}
How do I get the URL to go back to web.example.com/site
after going through this flow instead of showing as proxy.example.com/site
?
Thanks.