3

I want to map our system port 82 with 127.0.0.1:8080/runningSite and I am gettting exception with nginx config.

upstream dev {
    server 127.0.0.1:8080/runningSite;
}
server {
    rewrite_log on;
    listen [::]:81;
    server_name localhost;

    location / {
        proxy_pass  http://dev;
        proxy_set_header Host $http_host;
    }

}

Exception :

nginx: [emerg] invalid host in upstream "127.0.0.1:8080/runningSite" in C:\nginx -1.8.1/conf/nginx.conf:85

Can anyone please help me where I am wrong.

Sreekar Mouli
  • 1,313
  • 5
  • 25
  • 49
Charnjeet Singh
  • 3,056
  • 6
  • 35
  • 65

2 Answers2

6

You have the URI in the wrong place. It needs to go in the proxy_pass and not in the upstream block.

Try this:

upstream dev {
    server 127.0.0.1:8080;
}
server {
    rewrite_log on;
    listen [::]:81;
    server_name localhost;

    location / {
        proxy_pass  http://dev/runningSite/;
        proxy_set_header  Host $http_host;          
    }
}

See this document for details.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81
  • thanks for reply. But using this my inner file will be loaded like runningSite/resources/bootstrap/css/bootstrap.min.css is not access able – Charnjeet Singh Mar 10 '16 at 12:45
  • 1
    This is a great answer when someone want to redirect the uri from `/` to `/dev/blah/blah`, but at the same time you can use a loadbalancer and share the load among nodes. Amazing trick thanks a lot for the tip. For example: `upstream dev { least_conn; server 10.0.0.1:8080; server 10.0.0.2:8080; }` – Thanos Aug 11 '20 at 11:35
0

You can use location like this

location / {
      proxy_pass http://ttbth/home;
      proxy_set_header  Host $http_host;
    }
  • 1
    It is throwing me this error `"proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/default.conf` – gauravmehla Aug 30 '18 at 05:51