已解决:Django+uWSGI+Nginx+Let’s Encrypt无法访问HTTPS问题
I recently ran into a frustrating issue where I couldn't get HTTPS access working for my Django app hosted on uWSGI and Nginx, even after setting up Let's Encrypt certificates. Let me walk through what went wrong and how I fixed it.
The Problem
After configuring Let's Encrypt and setting up my custom Nginx config (project_rest.conf) linked to /etc/nginx/sites-enabled/, HTTPS connections just wouldn't work. Oddly enough, when I started uWSGI with uwsgi --ini uwsgi.ini (using my virtualenv setup), I could access the site just fine at mysitedomain.com:8000—so the app itself was running, but the HTTPS routing was broken.
What I Found
Digging into Nginx's configs, I realized the default enabled site file (/etc/nginx/sites-enabled/default) was still active. This file already had its own inbound traffic rules, and it was conflicting with my custom HTTPS setup. Nginx was prioritizing this default config over my project's rules, which meant my Let's Encrypt HTTPS settings weren't being applied at all.
The Fix
The solution was straightforward: delete the conflicting default enabled site file:
sudo rm /etc/nginx/sites-enabled/default
Then reload Nginx to make sure the changes take effect:
sudo systemctl reload nginx
Key Config Context
For reference, here's the setup I was working with:
project_rest.conf: My custom Nginx config for the Django project, which I had already linked to/etc/nginx/sites-enabled/(this includes all the HTTPS rules pointing to my Let's Encrypt certs)./etc/nginx/sites-available/default: The original default config file—you can keep this as a backup if you want, just don't leave it linked tosites-enabled.uwsgi.ini: My uWSGI config set up for the app's virtualenv, which worked perfectly when I launched it directly (hence the port 8000 access working).
Once I removed that default enabled site, my HTTPS config kicked in, and the site was accessible via https://mysitedomain.com without any issues.
内容的提问来源于stack exchange,提问作者Hide

