-1

I have nginx reverse-proxy to my site on IIS and here is my nginx config:

UPDATE

upstream backend  {
  server 43.128.77.101;
}

server {
  server_name domain.subdomain.com;   

  location /products {
    if ($query_string ~ Jeans){
      return 301 /get-all-products/?filter=jeans;
    }
    if ($query_string ~ Shirts){
      return 301 /get-all-products/?filter=shirts;
    }
    if ($query_string ~ Hats){
      return 301 /get-all-products/?filter=hats;
    }
  }

  location / {  
    proxy_pass  http://backend;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }   
}

It redirects from /products page to certain URLs by query string. But for page /products-available it fails with error 404. Nginx error log contains error:

"/usr/share/nginx/html/products-available" failed (2: No such file or directory)

The page /products-available doesn't need any redirections. I want it to pass on backend IIS server as it is. How can I tell nginx to pass it through? What am I doing wrong?

Thank you.

KozhevnikovDmitry
  • 1,660
  • 12
  • 27

1 Answers1

1

This would be because you are only defining the behavior of Nginx for a given path (/products).

If you want to define a default behavior for Nginx requests that don't match the /products path (like /products-available) you can add the following after your current location section to proxy any other path request to a different application/port.

location / {
    proxy_pass http://127.0.0.1:3000;
}

You can see more information on sending a request to a different application in https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/#passing-a-request-to-a-proxied-server

brakon
  • 51
  • 3