Nginx: “no ssl_certificate is defined for the listen … ssl directive” on custom port 8001
Sorry if this question was asked before but I tried the suggestions in there and still cannot resolved it.
I’m running Django project behind Nginx on my VPS. Main project is at https://myproject.com (port 443) and works like a charm.
I want to expose a second Django project at https://myproject.com:8001 but I couldn't load it on that address, I got the error mentioned in the title: no ssl_certificate is defined for the listen … ssl directive” on custom port 8001
For this, I updated /etc/nginx/sites-available/myproject to this (first part works fine for the main project at https://myproject.com, the second part is where I encounter some issues (marked with # NEW CONFIG FOR SECOND PROJECT (on :8001)
):
# Redirect all HTTP requests to HTTPS
server {
listen 80;
server_name myproject.com www.myproject.com;
return 301 https://$host$request_uri;
}
# Serve the app over HTTPS
server {
listen 443 ssl;
server_name myproject.com www.myproject.com;
ssl_certificate /etc/letsencrypt/live/myproject.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myproject.com/privkey.pem;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /home/myname/myproject/staticfiles/;
}
location /media/ {
alias /home/myname/myproject/media/;
access_log off;
expires 1h;
}
location / {
include proxy_params;
proxy_pass http://127.0.0.1:8000;
}
}
##########################################
# NEW CONFIG FOR SECOND PROJECT (on :8001)
# HTTP on :8001 → HTTPS on :8001
server {
listen 8001;
server_name myproject.com www.myproject.com;
return 301 https://$host:8001$request_uri;
}
# HTTPS on :8001 for second project
server {
listen 8001 ssl;
server_name myproject.com www.myproject.com;
ssl_certificate /etc/letsencrypt/live/myproject.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myproject.com/privkey.pem;
# Optional per-app static/media (comment out if not used)
location /static/ { alias /home/myname/project2/staticfiles/; }
location /media/ { alias /home/myname/project2/media/; access_log off; expires 1h; }
location / {
include proxy_params;
proxy_pass http://127.0.0.1:9001;
}
}