1

We are running a multinode application on different ports on a single server. We are trying to use nginx as a reverse proxy to route requests to the different applications, depending on the match of a string in the request URI.

We are using the location directive to match that string and route accordingly. If we return some value matching the strings in the location directive, it works fine. But as soon it is used in proxy_pass we only see a 402 error. What are we doing wrong?

Our config:

server {

                listen 443 ssl;
                listen [::]:443 ssl;
                server_name abc.xyz.co;
                include snippets/ssl-qaapp.xyz.co.conf;
                include snippets/ssl-params.conf;
                add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload; always';

location / 

{
        root /var/www/html/abc;
}

location ~ 3000 
{
#       proxy_pass https://127.0.0.1:3000;
        return 403;
        }
location ~ 3001 
{
#       proxy_pass https://127.0.0.1:3001;
        return 502;
       }
}
  • Please provide your configuration. – Gerald Schneider Jun 12 at 11:48
  • if i comment proxy_pass it works. If i comment return it through 402 error. – rabbi bhumbla Jun 12 at 12:07
0

with your configuration you can only reach your location if you query exactly https://abc.xyz.co/3000 or https://abc.xyz.co/3001.

When you are entering your matching location, nginx will proxy your request to your backend (=upstream) on exactly one of the URL https://127.0.0.1:3000 or https://127.0.0.1:3001.
If you get an HTTP answer code 402 it means that the corresponding backend returns it.

In other word, if you query https://abc.xyz.co/3000 or https://abc.xyz.co/3001 from your nginx server manually using wget or curl you will get the same return code.

  • Thanks, nothing wrong with the configuration. Node was replying 402. – rabbi bhumbla Jun 13 at 7:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.