NGINX - HA problem

I’m trying to access to my HA through nginx with https but doesn’t work.

If I access to http://private.ip:8123 works, but if I access to https://public.ip:443 the web stops on the first page before the login “Initializing” and the url is:

https://public.ip/frontend_latest/authorize.html?response_type=code&client_id=https://public.ip/&redirect_uri=https://public.ip/?auth_callback%3D1&state=eyJoYXNzVXJsIjoiaHR0cHM6Ly9qYWlyby5jZiIsImNsaWVudElkIjoiaHR0cHM6Ly9qYWlyby5jZi8ifQ%3D%3D

I have HA in raspbian server1, and NGINX in raspbian server2. THe two servers are in the same subnet without any comunication problems.

My HA configuration.yaml is:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 0
  longitude: 0
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: UTC
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.1.210
  base_url: public.ip

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
map:

# Track the sun
sun:

# Sensors
sensor:
  # Weather prediction
  - platform: yr

# Text to speech
tts:
  - platform: google

# Cloud
cloud:


logger:
  default: debug # default logging level
  logs:
    homeassistant.components.device_tracker.asuswrt: debug # suppress IPv6-related warnings; see https://github.com/home-assistant/home-assistant/issues/2814
    homeassistant.components.light.yeelight: info
    homeassistant.helpers.entity: debug # Hue bridge throws lots of errors


group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

This is my nginx.conf:

user www-data;
worker_processes 1;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        #gzip on;
        #gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        include /etc/nginx/proxy_params;
}

And this is my nginx domain conf:

server {
    # Update this line to be your domain
    server_name public.ip;

    # These shouldn't need to be changed
    listen 80 default_server ipv6only=off;
    return 301 https://$host$request_uri;
}

server {
    # Update this line to be your domain
    server_name public.ip;

    # Ensure these lines point to your SSL certificate and key
    ssl_certificate /etc/letsencrypt/live/public.ip/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/public.ip/privkey.pem;
    # Use these lines instead if you created a self-signed certificate
    # ssl_certificate /etc/nginx/ssl/cert.pem;
    # ssl_certificate_key /etc/nginx/ssl/key.pem;

    # Ensure this line points to your dhparams file
    #ssl_dhparam /etc/nginx/ssl/dhparams.pem;


    # These shouldn't need to be changed
    listen 443 default_server ipv6only=off;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
    ssl on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

    proxy_buffering off;

    location / {
#        auth_basic           "Zona restringida";
#        auth_basic_user_file /etc/nginx/.htpasswd;

        proxy_pass http://private.ip:8123;
        proxy_set_header Host $host;
        proxy_redirect http:// https://;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

I tried too with auth_basic enabled but the result is the same.

When I try to access I only see this in the nginx logs:

XX.XX.XX.XX - AUTH_BASIC_USER [28/Dec/2018:14:00:51 +0100] "GET / HTTP/1.1" 200 2874 "-" "Mozilla/5.0 (Windows NT 6.1; rv:64.0) Gecko/20100101 Firefox/64.0"

XX.XX.XX.XX - AUTH_BASIC_USER [28/Dec/2018:14:00:51 +0100] "GET /frontend_latest/app-6a2aa396.js HTTP/1.1" 499 0 "https://public.ip/" "Mozilla/5.0 (Windows NT 6.1; rv:64.0) Gecko/20100101 Firefox/64.0"

XX.XX.XX.XX - AUTH_BASIC_USER [28/Dec/2018:14:03:21 +0100] "GET /auth/authorize?response_type=code&client_id=https%3A%2F%2Fpublic.ip%2F&redirect_uri=https%3A%2F%2Fpublic.ip%2F%3Fauth_callback%3D1&state=eyJoYXNzVXJsIjoiaHR0cHM6Ly9qYWlyby5jZiIsImNsaWVudElkIjoiaHR0cHM6Ly9qYWlyby5jZi8ifQ%3D%3D HTTP/1.1" 302 0 "https://public.ip/" "Mozilla/5.0 (Windows NT 6.1; rv:64.0) Gecko/20100101 Firefox/64.0"

Any ideas about why doesn’t works and how I can resolve this?

Many thanks in advance.

Looking through my setup, I do not have the base_url in my HA config - maybe try removing that and see if it helps?

Now works with my original config without change nothing… it’s possible that the nginx or HA requires a little time to starts all?