I have a perfectly working nginx configuration that serves a django app which looks like this:
server {
listen 443 ssl;
server_name domain.de;
proxy_max_temp_file_size 0;
proxy_buffering off;
charset utf-8;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/domain.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.de/privkey.pem;
set $my_host $http_host;
if ($http_host = "domain.de") {
set $my_host "domain.de";
}
location / {
proxy_pass http://django:5000;
proxy_set_header Host $my_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80 ;
server_name domain.de;
return 301 https://domain.de$request_uri;
}
server {
listen 80 ;
server_name www.domain.de;
return 301 https://domain.de$request_uri;
}
server {
listen 443 ;
server_name www.domain.de;
return 301 https://domain.de$request_uri;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/domain.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.de/privkey.pem;
}
What I want to do is to add a new domain (let's say domain.com
). I already got the certificates. No matter how I add another serverblock I get a 400 response telling me that the certificate is not valid.
EDIT: I am running nginx in a docker-container:
nginx:
container_name: 'nginx'
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes: ##The following files are found on the linux server.
- /root/nginx-conf/hbe.conf:/etc/nginx/conf.d/default.conf
- /root/nginx-conf/main.conf:/etc/nginx/nginx.conf
- /etc/letsencrypt/live/domain.de/fullchain.pem:/etc/letsencrypt/live/domain.de/fullchain.pem
- /etc/letsencrypt/live/domain.de/privkey.pem:/etc/letsencrypt/live/domain.de/privkey.pem
- /etc/letsencrypt/live/domain.com/fullchain.pem:/etc/letsencrypt/live/domain.com/fullchain.pem
- /etc/letsencrypt/live/domain.com/privkey.pem:/etc/letsencrypt/live/domain.com/privkey.pem
depends_on:
- django
I tried or example to copy the main server-block adjusting the domain-name and the certificate location:
server {
listen 443 ssl;
server_name domain.de;
proxy_max_temp_file_size 0;
proxy_buffering off;
charset utf-8;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/domain.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.de/privkey.pem;
set $my_host $http_host;
if ($http_host = "domain.de") {
set $my_host "domain.de";
}
location / {
proxy_pass http://django:5000;
proxy_set_header Host $my_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443 ssl;
server_name domain.com;
proxy_max_temp_file_size 0;
proxy_buffering off;
charset utf-8;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
set $my_host $http_host;
if ($http_host = "domain.com") {
set $my_host "domain.com";
}
location / {
proxy_pass http://django:5000;
proxy_set_header Host $my_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I also tried copying the rest of the server blocks, adjusting the URL, but no matter how I do it, I still get a 400 bad request.
I'm really not an expert with nginx, would be very grateful if someone could lend me a hand. Thanks so much in advance!
0 Answers