Nginx reverse proxy (HomeAssistant beside Nextcloud)

Hello everyone,

becuase it tooked me some time to set up my server and to find the correct configuration, I likely would share my results here. Maybe it will help someone. My aim was to run HomeAssistant beside Nextcloud on the same server.

For the configuration of my Nextcloud I have followed the instructions on, so I am running NGINX as reverse proxy. HomeAssistant is installed as docker conitainer, following the installation instruction ( )

The config for the virtual host (NGINX):

upstream php-handler {
    server unix:/run/php/php7.4-fpm.sock;

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name  YYY.YYY.YYY.YY;

    root /var/www;

    location ^~ /.well-known/acme-challenge {
        default_type text/plain;
        root /var/www/letsencrypt;

        location / {
                return 301 https://$host$request_uri;

Remind to set your correct domains and replace YYY.YYY.YYY.YY by local IP of your server.

The NGINX-config for HomeAssistant:

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        # SSL configuration
        # RSA certificates
        ssl_certificate /etc/letsencrypt/;
        ssl_certificate_key /etc/letsencrypt/;
        # ECC certificates
        ssl_certificate /etc/letsencrypt/;
        ssl_certificate_key /etc/letsencrypt/;

        # This should be ca.pem (certificate with the additional intermediate certificate)
        # See here:
        # ECC
        ssl_trusted_certificate /etc/letsencrypt/;

    # Include SSL configuration
        include /etc/nginx/snippets/ssl.conf;

        # Include headers
    include /etc/nginx/snippets/headers.conf;

    location / {
        proxy_pass http://YYY.YYY.YYY.YY:8123;
        proxy_set_header Host $host;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

So, NGINX is listing here for requests on and is forwarding this to it’s own local IP on port 8123.

For SSL I am using Letsencrypt and cerificates are generated by (same steps like shown at website )

And for the HomeAssistant configuration.yaml I have added:

  server_port: 8123
  external_url: ""
  internal_url: "http://homeassistant.local:8123"

With this config I can host both services, Nextcloud and HomeAssistant, on the same server and both services are secured by SSL.

Hope this helps.

Hello Lars,

thank you for your tutorial. It helped me a lot with my setup. I only have problems with creating certificates for my second webserver (Home Assistant), because ACME always uses the owner name of my first domain. Due to the HSTS Security Headers I always get a SSL_ERROR_BAD_CERT_DOMAIN error when trying to access my second domain.



it’s a long time ago, but I think I just created a new certificate.
I am using a second user called “letsencrypt” for creating all certificates.

su - letsencrypt --set-default-ca --server letsencrypt
chmod -R 775 /var/www/letsencrypt
mkdir -p /etc/letsencrypt/
mkdir -p /etc/letsencrypt/
chown -R www-data:www-data /etc/letsencrypt
chmod -R 775 /etc/letsencrypt

su - letsencrypt --issue -d --server letsencrypt --keylength 4096 -w /var/www/letsencrypt --key-file /etc/letsencrypt/ --ca-file /etc/letsencrypt/ --cert-file /etc/letsencrypt/ --fullchain-file /etc/letsencrypt/ --reloadcmd "sudo /bin/systemctl reload nginx.service" --issue -d --server letsencrypt --keylength ec-384 -w /var/www/letsencrypt --key-file /etc/letsencrypt/ --ca-file /etc/letsencrypt/ --cert-file /etc/letsencrypt/ --fullchain-file /etc/letsencrypt/ --reloadcmd "sudo /bin/systemctl reload nginx.service"


Be sure to replace the domain by your correct domain everywhere. Best is to copy and paste it in a texteditor and search for the string “meinedomain” to be sure.

With this you should get multiple certificates and every certificate should be stored in the folders /etc/letsencrypt/XXX

Hope this helps.


Hey Lars,

thanks for your response, this was the way i tried. As a workaround, i first created an RSA and ECC Certificate for my base Domain (in your example “”). So for all other Certificates, the owner was


Hello ElLarso,

thank you very much for sharing your information! I am quite new to HA. Before I had run OH2 and nextcloud sucessfully on one machine.

Did your config also works with a HA installation as docker composed? I want to have the benefits from the docker composed (esp. the Add-Ons).

I am running Debian 11 on a older i3-NUC that was connected to my TV, and I was quite happy to have only one PC for my Home, my (next)Cloud and looking in the Internet.



to be honest, I am not sure but I would guess that it should work. As far as I understand, the following lines, just forward your request to the local IP-address (of your server) on port 8123.

Your docker should handle everything and listen to this port. As I do understand, there should not be a difference between docker and docker-compose. Therefore, I do guess that it should work.