Answer the question
In order to leave comments, you need to log in
How to make friends nginx docker (vaultwarden) and certbot?
Hello.
There is a server with Ubuntu 20.04, nginx and certbot packages are installed on it. This server also runs the vaultwarden doker container.
The container is launched with the settings:
sudo docker run -d --name vaultwarden -e \
DOMAIN=https://под.домен.ру -e SIGNUPS_ALLOWED=false \
-v /vw-data/:/data \
-e WEBSOCKET_ENABLED=true \
-p 80:80 -p 3012:3012 --restart on-failure \
vaultwarden/server:latest
server {
server_name под.домен.ру; # managed by Certbot
location / {
proxy_pass http://под.домен.ру:80;
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;
}
location /notifications/hub {
proxy_pass http://под.домен.ру:3012;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /notifications/hub/negotiate {
proxy_pass http://под.домен.ру:80;
}
# Optionally add extra authentication besides the ADMIN_TOKEN
# If you don't want this, leave this part out
location /admin {
# See: https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
auth_basic "Private";
auth_basic_user_file /path/to/htpasswd_file;
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;
proxy_pass http://под.домен.ру:80;
}
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/под.домен.ру/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/под.домен.ру/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
# if ($host = под.домен.ру) {
# return 301 https://$host$request_uri;
# } # managed by Certbot
# listen 80 ;
# listen [::]:80 ;
# server_name под.домен.ру;
# return 404; # managed by Certbot
}
certbot renew --dry-run
...
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: subdomain.ru
Type: unauthorized
Detail: Invalid response from
http://subdomain.ru/.well-known/acme-challenge/ nLO...
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
}
certbot -w /var/www/letsencrypt
Answer the question
In order to leave comments, you need to log in
The redirect on the nginx side will not work, not because it is commented out, but because nginx here does not listen to requests on port 80 at all, and well, it cannot make any kind of redirect. Hence the problems with certbot on http - the request goes directly to the container.
It would be better to elevate the container to 127.0.0.1:80 for example. In nginx, make two server sections:
one for external_ip:80 - it only has a redirect
; the other external_ip:443 - it contains the same as it is now.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question