0

I've a problem with my nginx :

I have to redirect all the http and https traffic when my users search "hermes.my-domain.com" to the 5000 port, on my nginx serveur, where my app is.

"hermes" is the name of my sub-domain.

So I do that :

server {

listen    80;
server_name    hermes.my-domain.com;

return 301 https://hermes.my-domain.com$request_uri;
} 

server {

listen    443;
ssl_certificate           /etc/certs/ssl/bundle.crt;
ssl_certificate_key       /etc/certs/ssl/server.key;

    location / {
        proxy_pass http://localhost:5000;
        proxy_redirect off;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Ssl on;
    }
}

Every time I fall on a 502 error.

I don't understand what's happen...

if someone know the problem please ?

Thank you very much !

This is my result from error.log :

My apologies, this is my result from error.log :

    2021/11/24 09:09:44 [error] 19384#19384: *332 connect() failed (111: Connection refused) while connecting to upstream, client: 10.10.1.158, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "hermes.my-domain.com"

2021/11/24 09:09:44 [error] 19384#19384: *332 connect() failed (111: Connection refused) while connecting to upstream, client: 10.10.1.158, server: , request: "GET / HTTP/1.1", upstream: "http://[::1]:5000/", host: "hermes.my-domain.com"

2021/11/24 09:09:44 [error] 19384#19384: *332 no live upstreams while connecting to upstream, client: 10.10.1.158, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://localhost/favicon.ico", host: "hermes.my-domain.com", referrer: "https://hermes.my-domain.com/"

Thank you for your help all !

nickola2
  • 1
  • 2
  • 1
    If that is an exact copy-paste, note that you currently have `location /{` and probably mean to have `location / {`. Often `nginx` will put something in `error.log` - maybe you could post if there is something there. – Paul Nov 23 '21 at 14:28
  • 1
    Thank you for your reply. I put a space between "/{" in my vhost file, but it's the same result. And I add a log output, and this is the result : 10.10.1.158 - - [23/Nov/2021:17:16:17 +0100] "GET / HTTP/1.1" 502 568 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36". – nickola2 Nov 23 '21 at 16:42
  • 1
    normally use `listen 443 ssl;` or `listen 443 ssl http2;` never read about ssl on – djdomi Nov 23 '21 at 18:48
  • 1
    The output above is from `access.log`. Please edit the question and add contents of `error.log` when the error occurs. – Tero Kilkanen Nov 23 '21 at 19:36
  • 1
    `connection refused` indicates that nothing is listening on port 5000. Make sure your service is running and listening on the correct port and interface. You can do that by running `ss -tnlp |grep :5000`. – Gerald Schneider Nov 24 '21 at 08:21
  • Oh okay, so if I understand well, it's not my Vhost the problem, but rather my web app is not correctly working on my 5000 port ? – nickola2 Nov 24 '21 at 08:39
  • It's a possibility. We can't say for sure without seeing the output of said command. – Gerald Schneider Nov 24 '21 at 08:45
  • The result is nothing, I do some test on other port what I know active, and I have a result, but for ss -tnlp |grep :5000, I have nothing. So I think you're right ! And the problem is more on my web app. Thank you so puch for your answer and help – nickola2 Nov 24 '21 at 08:58

1 Answers1

1

Your application server is not listening on Port 5000.

connection refused indicates that nothing is listening on that port on that interface.

An empty output of ss -tnlp |grep :5000 confirms that nothing is listening on that port.

If your application server is indeed running, check it's configuration for the correct port. If it is not running, start it.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89