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?


  • This configuration looks correct. Exactly what are you seeing that is a problem? Be specific. – Michael Hampton Jun 16 at 16:03
  • @MichaelHampton the problem is that the proxy's URL is exposed. Why is that happening? I want the URL to remain web.example.com. – simplehuman Jun 16 at 17:21
  • What exactly do you mean? The vague description is useless. – Michael Hampton Jun 16 at 17:24
  • The URL in the location bar of the browser changes from web.example.com to proxy.example.com so the end users can see the URL of the proxy. I don't think that's supposed to happen – simplehuman Jun 16 at 17:27
  • 2
    OK, now I get it. That isn't caused by nginx though; that's your backend. – Michael Hampton Jun 16 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.