0

Here is what I need, when its localhost:80 I need Nginx welcome page to be served, but when its localhost:80/pass, my application(react app) to be served, here is my Nginx.conf looks like,

    server {
    listen       80;
    server_name  localhost;
    location /pass {
        root   build;
        index  index.html index.htm;
        proxy_pass http://localhost:3000;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

am I missing something, because it's serving me this

An error occurred. Sorry, the page you are looking for is currently unavailable. Please try again later.If you are the system administrator of this resource then you should check the error log for details.Faithfully yours, nginx.

here is my error.log

2020/09/19 21:54:00 [error] 10888#1388: *35 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /pass HTTP/1.1", upstream: "http://[::1]:3000/", host: "localhost"

2020/09/19 21:54:39 [error] 10888#1388: *35 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /pass HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "localhost"
Deekshith MR
  • 73
  • 3
  • 10
  • Can you add corresponding error log entries to your question? Also, with this configuration request to `http://localhost/pass` would be passed to your backend as `http://localhost:3000/pass`, not as `http://localhost:3000/`, is this what you expecting? – Ivan Shatsky Sep 19 '20 at 16:46
  • ill be just passing ```http://localhost:3000/``` to backend – Deekshith MR Sep 19 '20 at 16:52
  • Can you post the error logs? – Naman Arora Sep 19 '20 at 16:54
  • Try adding trailing slash to your `proxy_pass` directive: `proxy_pass http://localhost:3000/;`. Read [this](https://stackoverflow.com/questions/53649885/a-little-confused-about-trailing-slash-behavior-in-nginx/53650827#53650827) answer for explanation. – Ivan Shatsky Sep 19 '20 at 16:57
  • added last 2 error log @NamanArora – Deekshith MR Sep 19 '20 at 17:00
  • I did that as well @IvanShatsky, didn't work – Deekshith MR Sep 19 '20 at 17:01
  • I see, your backend refused connection. I think you would need this trailing slash anyway, but your current problem related to something else. Is `http://localhost:3000` accesslible from command line via `curl`? – Ivan Shatsky Sep 19 '20 at 17:04

0 Answers0