Search code examples
nginxdnssubdirectory

Trying to root a domain with Nginx under a sub-folder


I have a domain tmhos.church and a simple index.html located at cosmoscomputers.com:3597/ref/tmhos. (they're on the same digital ocean droplet server & dns)

I'm trying to hide tmhos.church so that it appears to be its own website, while actually being at above /ref/tmhos.

I have found this article How to preserve request url with nginx proxy_pass (close i think, but not exactly my problem) and have an nginx config that looks like below... but when i go to tmhos.church, it goes to the top of cosmoscomputers.com (but does keep the tmhos.church domain in the address bar (good)). If I then manually add /ref/tmhos to the end, it goes to the page i want to be the root. I confess i don't know what ALL the lines are doing (eg the 'rewrite' regex), but the proxy_pass isn't doing exactly what i want.

server {
    listen 80;
    listen [::]:80;

    server_name tmhos.church www.tmhos.church;

    location / {

        rewrite            ^(.*)$   "://$http_host$uri$is_args$args";
        rewrite            ^(.*)$   "http$uri$is_args$args" break;
        proxy_set_header   Host     $host;

        proxy_pass http://138.197.133.227:3597/ref/tmhos;

    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Solution

  • Can you please try:

    server {
        listen 80;
        listen [::]:80;
    
        server_name tmhos.church www.tmhos.church;
    
        location / {
            proxy_set_header Host $host;
            proxy_pass http://cosmoscomputers.com:3597/ref/tmhos/;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }