Homer as default site in NGINX

This is mentioned in the Homer section, but I couldn’t figure out how by looking at various topics I searched here.

The DietPi installation hostname is services, and it has static DNS entries for both that & homer pointing to it.

I would like to be able to access Homer via http://homer/ and not http://homer/homer/, and keep http://services/ for other things.

With hostnames this is not possible, a hostname points to an IP.
What you want is a webserver/reverse proxy with two different domains.

In nginx i would be looking something like:

server {
    listen 80;
    server_name homer;

    location / {
        proxy_pass http://localhost/homer/;
        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;
    }
}

server {
    listen 80;
    server_name services;

    # Your existing configuration for other services
    location / {
        proxy_pass http://localhost/; 
        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;
    }
}
1 Like

I tried adding this on top of /etc/nginx/sites-available/default

server {
        listen 80;
        listen [::]:80;
        server_name homer homer.lan;

        location / {
                proxy_pass http://localhost/homer/;
                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;
        }
}

But when I go to homer.lan I get the default nginx page and homer.lan/homer is a broken homer instance.

The code above was just a boilerplate, I don’t know what you need to get homer working behind a reverse proxy. ChatGPT generated the following, so no guarantee it is working:

server {
    listen 80;
    listen [::]:80;
    server_name your_domain.com;

    location /homer {
        proxy_pass http://localhost/homer;
        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_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }

    location /socket.io {
        proxy_pass http://localhost/homer/socket.io;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    # Add any additional configurations or server blocks as needed
}

You can also use nginx proxy manager for this, if you like.

why are you doing it that complicate :smiley:

It would be much easier to create a new server block (vHosts) How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04 | DigitalOcean

  1. nano /etc/nginx/sites-available/homer
  2. add following
server {
        listen 80;
        listen [::]:80;

        root /var/www/homer;
        index index.html index.htm index.nginx-debian.html;

        server_name homer.lan;

        location / {
                try_files $uri $uri/ =404;
        }
}
  1. save & exit
  2. ln -s /etc/nginx/sites-available/homer /etc/nginx/sites-enabled/
  3. systemctl restart nginx.service
  4. done
1 Like

Thanks, worked perfectly!

Maybe add it to the Homer instructions?