murtaza52
murtaza52

Reputation: 47431

nginx isnt forwarding to static server

I have two servers running in the background, I would like nginx to reverse proxy to both of them.

I want nginx to run on port 80. When a user navigates to http://localhost:80/, he should be forwarded to http://localhost:3501. However I am still seeing the default nginx page at http://localhost:80. I have nginx installed on my localhost, and am testing from the same box.

server {
               listen 80;
               server_name _;

               location ^~/api/* {
                       proxy_pass http://localhost:8000;
               }
               location ^~/* {
                       proxy_pass http://localhost:3501;
               }
       } 

Upvotes: 0

Views: 81

Answers (1)

Xiaomao Lan
Xiaomao Lan

Reputation: 11

  1. Add upstream:
    upstream backend-testserver {
    server 127.0.0.1:3501 weight=1 max_fails=2 fail_timeout=30s; # server 1
    server 127.0.0.1:3502 weight=1 max_fails=2 fail_timeout=30s; # server 2
    }

  2. Add proxy_pass in "server -> location":
    location / {
    root html;
    index index.html index.htm;
    proxy_pass http://backend-testserver;
    }

Upvotes: 1

Related Questions