0

I have the following configuration:

server {

    listen: 8080;
 
    location / {
        proxy_pass           https://somehost.abc.xyz;
        proxy_redirect       off;
        proxy_set_header     Host somehost.abc.xyz;
        proxy_set_header     X-Real-IP somehost.abc.xyz;
        proxy_set_header     X-Forwarded-For somehost.abc.xyz;
        proxy_set_header     X-Forwarded-Host somehost.abc.xyz;
        proxy_set_header     HELLO pizza;
    }

}

Whenever I hit the proxy, let's say I go to http://localhost:8080/home, I get 503 service unavailable (not from the nginx service, from the app I'm trying to go to https://somehost.abc.xyz/home).

But if I just go to https://somehost.abc.xyz/home or do a redirect return 301 https://somehost.abc.xyz/home; it's all good and I get to the app. Although this doesn't help me, because I want to get there through the proxy so I can add a request header to every request that goes through.

Any ideas what could possibly cause this and how to solve it?

14
  • Check your application's logs. Jul 15, 2021 at 17:01
  • @MichaelHampton somehost.abc.xyz is not my application, i should have stated it in the question
    – kevin
    Jul 15, 2021 at 17:05
  • 1
    You will have to contact whoever runs that application for assistance. Jul 15, 2021 at 17:07
  • 1
    If he doesn't know, then nobody else has any hope. I think he is just trying to get rid of you. He is certainly capable of knowing why it doesn't work. If he did not investigate, then he probably doesn't want you to do what you are trying to do. Jul 15, 2021 at 17:10
  • 1
    You will have to work that out with him somehow. Jul 15, 2021 at 17:16

2 Answers 2

1

Try to use backend port on proxy_pass address, and is it header "HELLO" is valid to backend app?

server {
            listen: 8080;
     
            location / {
                proxy_pass          https://somehost.abc.xyz:443;
                proxy_redirect      off;
                proxy_set_header    Host                somehost.abc.xyz;
                proxy_set_header    X-Real-IP           $remote_addr;
                proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header    X-Forwarded-Host    your.host.address;
                proxy_set_header    HELLO               pizza;
    
                
                proxy_ssl_server_name   on;
                proxy_ssl_name      somehost.abc.xyz;
                # Optional
                proxy_ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
                proxy_ssl_ciphers   'Required SSL Ciphers';
                proxy_ssl_trusted_certificate   "/path/to/your/ca-cetificates.crt";
            }
        }

EDIT: using SSL Backend you should define proxy_ssl_name if you don't have backend ssl certs

2
  • as stated, the user tries to rpoxy someone else server. adding a oort to a default request on a default port is not required and can lead in some situations to a totally different goal
    – djdomi
    Apr 19, 2022 at 17:44
  • i see.. the problem is he/she tries to reverse proxy on SSL protocol, should use proxy_ssl_protocols and ciphers, also proxy_ssl_name Apr 20, 2022 at 18:49
1

I have had a similar problem and I've found that the following statement caused the 503s:

 proxy_set_header     Host $host;  # same for $http_host;

Since it wasn't necessary for our use case, I was able to just remove it and by that, got rid of the 503s and got nginx to finally make the requests to the upstream server.

I have since also learned that it seems to be the use of the $host variable, not the statement itself that caused the issue for us, which means my answer might not really be to the point.

Setting a fixed value (in this case inside a server block) doesn't create the problem.

I don't have an explanation though, I'm hoping that someone else might by able to shed some light on this. This used to work in nginx 1.14 and I also believe in 1.16, but no longer in either 1.18 and up.

1
  • This helped. I hit the same 503 issue, commenting this proxy_set_header Host $host line resolved it. Not clear why its causing the issue Feb 2 at 1:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .