I configured Nextcloud on a Raspberry Pi 4 running Ubuntu Server 18.04.4 64-bit, following Carsten Rieger guide so now on the Pi is installed and running nginx. Then, using Mailu configuration I installed a mail server with Docker Compose. I chenged standard configuration because conflicting ports 80 and 443 used by "native" nginx and "docker container" nginx, so in container I use 8080 and 8443.
How must I configure native nginx so when I visit my mail.mydomain.com redirect to 8080 and 8443 ports? How can obtains certificates for HTTPS for mail.mydomain.com with Let's Encrypt?
If I understand your problem correct, you like to use the nginx on the host as a proxy server to redirect traffic to the docker container.
Extend your nginx.conf on the host:
http {
...
# redirect http to https from your domain
server {
listen 80;
server_name localhost, <your domain>, <secondary domain>;
return 301 https://<your domain>$request_uri;
}
# simple reverse-proxy
server {
listen 443;
server_name localhost, <your domain>, <secondary domain>;
ssl on;
# if you use let's encrypt (certbot) /etc/letsencrypt/live/<your domain>/fullchain.pem
ssl_certificate <path to certificate>;
# if you use let's encrypt (certbot) /etc/letsencrypt/live/<your domain>/privkey.pem
ssl_certificate_key <path to key>;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
client_max_body_size 200M;
# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
}
...
}
To Your second question, yes you can use Let's Encrypt to obtain the certificate. Either as standalone or with the nginx plugin.
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx
Obtain your certificate without nginx plugin (you need to stop the nginx first because certbot uses the port 80)
$ sudo certbot certonly --standalone -d <your domain> -d <secondary domain>
Obtain your certificate with the nginx plugin
$ sudo certbot --nginx -d <your domain> -d <secondary domain>
In any case you need to reload the nginx after a certificate was retrieved or renewed:
$ sudo service nginx reload