-3

I am trying to set up Https for my Ubuntu server using Nginx. I am running an application on localhost and using reverse proxy. This is my first time using Linux and nginx. My https request is failing everytime. I will try to include as many relevant details from the server:

I have assigned a domain name to my site and have configured the ssl certificates using certbot.

When I make a request using http, it is successful: curl request to http port

However, https requests always fail: curl request to https port

Both ports 443 and 80 are active and listening: active ports

In order to make debugging simple I have now configured nginx to redirect http requests(port 80) to https (port 443). This means requests made to my http now also fail. This is my site's configuration file now: nginx conf file

The following is a snippet of the nginx debug log after I made an https request:

2024/12/28 18:27:40 [debug] 21424#21424: *207 http script copy: "https://" 2024/12/28 18:27:40 [debug] 21424#21424: *207 http script var: "chatbot.sweatsupport.site" 2024/12/28 18:27:40 [debug] 21424#21424: *207 http script var: "/ws/socket.io/?EIO=4&transport=polling&t=PGEXYJx" 2024/12/28 18:27:40 [debug] 21424#21424: *207 http finalize request: 301, "/ws/socket.io/?EIO=4&transport=polling&t=PGEXYJx" a:1, c:1 2024/12/28 18:27:40 [debug] 21424#21424: *207 http special response: 301, "/ws/socket.io/?EIO=4&transport=polling&t=PGEXYJx" 2024/12/28 18:27:40 [debug] 21424#21424: *207 http set discard body 2024/12/28 18:27:40 [debug] 21424#21424: *207 HTTP/1.1 301 Moved Permanently Server: nginx/1.24.0 (Ubuntu) Date: Sat, 28 Dec 2024 18:27:40 GMT Content-Type: text/html Content-Length: 178 Connection: keep-alive Location: https://chatbot.sweatsupport.site/ws/socket.io/?EIO=4&transport=polling&t=PGEXYJx 

What I have interpreted from the log is that a 301 http response is made. There seems to be no upstream logs showing any requests to localhost:8000. I do attempt to understand the log but that lead to more confusions so I will not mention that.

I have been stuck on this error for 3 days and have browsed the most forums I could but to no avail. Please do let me know if you need any more information. I would be grateful for any advice.

5
  • what error do you get if you curl against localhost:8000 ? Can you change proxy_pass http://localhost:8000 to proxy_pass http://localhost and restart nginx and try again using https? It seems like https connection are redirecting to localhost:8000 Commented Dec 28, 2024 at 20:19
  • proxy_pass should be set to whatever port your app is running. since localhost worked before setting up ssl then means your app is running on port 80. so proxy_pass http://localhost should be valid. Test it Commented Dec 28, 2024 at 20:44
  • 1
    for 3 days in that three days, did you test without the proxy? Did it work? Info 101. Commented Dec 29, 2024 at 4:52
  • PowerShell curl command isn’t the real one. You’d better use your Ubuntu terminal to execute curl and also enable its logging to dig further into the issue. Alternatively, OpenSSL command line can be used to debug HTTPS issues. Commented Dec 29, 2024 at 10:17
  • @GregAskew Apologies for the late response, please check the corrected answer that I published to know how I fixed it. The problem was not with the nginx configuration at all. Commented Jan 4 at 16:59

2 Answers 2

0

redirecting 80 to 443 is not a good move. I'd suggest scrapping your setup and starting over from the beginning instead of running yourself in circles.

Try starting from good instructions, step by step, and notice if you skipped anything.

Basic advice, but trust me, you missed a step or two and will save hours by starting over.

1
  • The configuration was all right. The problem was with the AWS server I was using, more info about this in the corrected answer I published. Commented Jan 4 at 16:56
0

It turns out the problem was not with the Nginx configuration at all but with my AWS LightSail server firewall. The funny part is that the CLI showed that the server firewall was off but the firewall has to be configured via GUI on the AWS site. I fixed it by adding the HTTPS port (443) to the firewall via the Networking tab in the server settings
(Click on server->Networking tab->IPv4 Firewall->Add rule->enter port 443)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.