For those of you who are familiar with unRAID and SWAG will know its an excellent bit of kit for using as a reverse proxy however there are no examples of using the EXTRA_DOMAINS variable with two or more sites. The guide will based on my current setup. I currently have four domain names, one linked to Oragnizr and three linked to Ghost Blogs.

The first stage is to add your extra domain as normal to the SWAG docker, make sure they are separated by commas only. Apply the changes to the docker.

Now go to your appdata/swag/nginx/site-confs/ and open up the default.conf file. I find the easiest way to edit the SWAG .conf files is to use WinSCP with it's built in editor but other options exit such as Notepad++ or Visual Code Studio, you can then link your desired editor with WinSCP to edit the files.

You should having something similar to the block below in the default.conf file.

# redirect all traffic to https
server {
listen 80;
listen [::]:80;
server_name domain1.com;
return 301 https://$host$request_uri;
}

# main server block
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

server_name domain1.com;

# all ssl related config moved to ssl.conf
include /config/nginx/ssl.conf;

client_max_body_size 0;

# enable subfolder method reverse proxy confs
include /config/nginx/proxy-confs/organizr.subfolder.conf;

}

# enable subdomain method reverse proxy confs
include /config/nginx/proxy-confs/*.subdomain.conf;
# enable proxy cache for auth
proxy_cache_path cache/ keys_zone=auth_cache:10m;

You'll want to copy everything down from line 1 to 19. Now create another blank .conf file in the same directory, name it anything you wish, and paste the copied code in there. Rename the "server_name" section to whatever your second domain is.

server {
listen 80;
listen [::]:80;
server_name domain2.com;
return 301 https://$host$request_uri;
}

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

server_name domain2.com;	

# all ssl related config moved to ssl.conf
include /config/nginx/ssl.conf;

client_max_body_size 0;

The next section will depend entirely on what you want the second domain to route to. In my case its a ghost blog docker so I've implemented the block that would normally go in the "proxy-confs" file in here just to make things easier.

  location / {
    include /config/nginx/proxy.conf;
    resolver 127.0.0.11 valid=30s;
    set $upstream_app ghostblog1;
    set $upstream_port 2368;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    proxy_redirect off;
  }
}

I'm running three ghost dockers with internal docker DNS resolution so all I have to change is the $upstream_app variable to match the dockers name. Note that the $upstream_port stays as per the default in all cases as they all have different docker IP's. The whole block should turn out like this...

server {
listen 80;
listen [::]:80;
server_name domain2.com;
return 301 https://$host$request_uri;
}

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

server_name domain2.com;	

# all ssl related config moved to ssl.conf
include /config/nginx/ssl.conf;
    
client_max_body_size 0;

location / {
    include /config/nginx/proxy.conf;
    resolver 127.0.0.11 valid=30s;
    set $upstream_app ghostblog1;
    set $upstream_port 2368;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    proxy_redirect off;
  }
}

If you want to proxy to a service on another machine then your .conf should look something like the block below. Just change the proxy_pass IP and port to suit.

server {
listen 80;
listen [::]:80;
server_name domain2.com;
return 301 https://$host$request_uri;
}

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

server_name domain2.com;	

# all ssl related config moved to ssl.conf
include /config/nginx/ssl.conf;
    
client_max_body_size 0;

location / {
    include /config/nginx/proxy.conf;
    resolver 127.0.0.11 valid=30s;
    proxy_pass http://192.168.1.171:80;
  }
}

Restart SWAG and check the log just in case you've missed typed something.

Simply rinse and repeat for as many domains as you want.