I am running nginx for a static website and an email server, and apache2 for a nextcloud instance on a remote debian 10 server.
I want to use ssl for both. I have set up apache2 to listen on port 8443 instead of 443 for ssl and 8080 instead of 80 for http.
I have successfully applied certbot
on both servers.
However, if I now go to https://nextcloud.mydomain.com (where apache sits), I still get "Warning: Potential Security Risk Ahead". Testing with this site reveals: The sites I run with nginx are the ones the certificate is valid for. I guess this is because the https-prefix causes my browser to ask port 443, not 8443.
How can I solve this?
Relevant file contents:
/etc/nginx/sites-available/mysite
:
server {
root /path/to/website;
index index.html index.htm ;
server_name mydomain.com www.mydomain.com ;
location / {
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/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
}
server {
if ($host = www.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name mydomain.com www.mydomain.com ;
return 404; # managed by Certbot
}
/etc/apache2/ports.conf
:
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 8080
<IfModule ssl_module>
Listen 9000
</IfModule>
<IfModule mod_gnutls.c>
Listen 8443
</IfModule>
<IfModule mod_ssl.c>
Listen 8443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I changed the port ssl_module above to 9000 because making them all 8443 gave me an error.
Start of both /etc/apache2/sites-available/000-default.conf
and /etc/apache2/sites-available/nextcloud.conf
:
<VirtualHost *:8080>
[...]
Start of both /etc/apache2/sites-available/default-ssl.conf
and /etc/apache2/sites-availble/nextcloud-le-ssl.conf
:
<IfModule mod_ssl.c>
<VirtualHost *:8443>
[...]
All 4 files have a symlink in /etc/apache2/sites-enabled
.
http://www.example.com:8080/blah
orhttps://www.example.com:8443/bleh