implementing Nginx SSL configuration leading to '421 Misdirected Request' on Ubuntu 22.04
I recently switched to I'm testing a new approach and I'm trying to configure I'm working through a tutorial and I'm building a feature where I'm working on a personal project and I'm currently working with an scenario with my Nginx setup on an Ubuntu 22.04 server where I have enabled SSL for my sites..... After configuring the SSL certificates, I started receiving a '421 Misdirected Request' behavior when trying to access my site over HTTPS. My configuration for the server block looks like this: ```nginx server { listen 80; server_name example.com www.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name example.com www.example.com; ssl_certificate /etc/ssl/certs/fullchain.pem; ssl_certificate_key /etc/ssl/private/privkey.pem; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ``` I've ensured that the SSL certificates are valid and properly located, and I've verified that the service on port 3000 is running correctly. When I check the Nginx behavior log, I see the following message: ``` 2023/10/14 12:34:56 [behavior] 12345#0: *1234 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: example.com, request: "GET / HTTP/2.0", upstream: "http://localhost:3000/", host: "example.com" ``` The connection to the upstream server seems to be failing, but when I curl the service directly on port 3000, it responds as expected: ```bash curl http://localhost:3000 ``` This returns the correct content. I've tried restarting Nginx and the upstream application multiple times, but the question continues. It seems like Nginx is either misconfigured or not able to communicate with my application on port 3000. Any insights on what could be causing this '421 Misdirected Request' behavior and how to resolve it would be greatly appreciated! This is part of a larger CLI tool I'm building. I'm on macOS using the latest version of Nginx. I appreciate any insights! I'm developing on Linux with Nginx. Any feedback is welcome! The project is a microservice built with Nginx. What's the best practice here? I'm coming from a different tech stack and learning Nginx. Any feedback is welcome! I'm on Ubuntu 22.04 using the latest version of Nginx. Any help would be greatly appreciated! Hoping someone can shed some light on this. This is part of a larger service I'm building. What are your experiences with this?