Score:0

How to redirect my sub-domain to localhost:5000 in Https with Nginx?

us flag

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 !

Paul avatar
cn flag
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.
us flag
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".
djdomi avatar
za flag
normally use `listen 443 ssl;` or `listen 443 ssl http2;` never read about ssl on
us flag
The output above is from `access.log`. Please edit the question and add contents of `error.log` when the error occurs.
in flag
`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`.
us flag
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 ?
in flag
It's a possibility. We can't say for sure without seeing the output of said command.
us flag
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
Score:1
in flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.