Subdomain behind SWAG

Heya,
I’m using SWAG in front of Nextcloud and Wireguard. I understand that I can put files in config/www to see them in mydomain.com root. But how could I make subdomain.mydomain.com and point to a different directory, for example config/www/subdomain? This is probably very simple, but I am even simpler.

EDITED TO ADD: my nextcloud is in cloud.domain.com

Here’s a simple way to do it. For this example I will be creating the subdomain foobar.example.com

BTW, paths are all relative to the SWAG container’s storage mount point.

Create a new configuration file for your subdomain .../config/nginx/site-confs/foobar.subdomain.conf with the following content:

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

       root /config/www/foobar;
       index index.html index.htm index.php;

       server_name foobar.*;

       include /config/nginx/ssl.conf;

       client_max_body_size 0;

       location / {
#               auth_basic "Restricted";
#               auth_basic_user_file /config/nginx/.htpasswd;
               include /config/nginx/proxy.conf;
       }
}

NB: You should replace both instances of foobar with your chosen subdomain.

The key lines in this configuration file are:

  • root which tells nginx in which directory the content for the subdomain is located, and
  • server_name which tells nginx which web requests should be processed by this particular server { ... } block. In this case the expression foobar.* tells nginx to match any domain beginning with foobar. (as the * is the match any character wildcard).

Save this file and exit your text editor. Copy your content for the subdomain to the location given in root and restart the swag container. You should now be able to access your subdomain https://foobar.example.com

hope this works for you!

Thanks for the reply. Now it works, I just had a forgotten container running with the same subdomain, I removed that from my docker-compose and now everything is running nicely. :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.