Setup Virtualmin with nginx and a custom domain

  1. In webmin, create a virtual server for your panel, eg webmin.example.com and usermin.example.com
  2. Go to Webmin > Webmin Configuration > Ports and Addresses, set Web server hostname to webmin.example.com
  3. Go to Webmin > Usermin Configuration > Ports and Addresses, set Web server hostname to usermin.example.com.
    3.2. In case you want usermin hosted on a same domain but a different path to webmin (eg webmin.example.com for webmin and webmin.example.com/ucp/ for usermin) just enter webmin.example.com
  4. Edit nginx server configuration file for domain webmin.example.com
upstream webmin-upstream {
	server localhost:10000;
}
upstream usermin-upstream {
	server localhost:20000;
}
server {
...
    location /ucp/ {

		# set some headers and proxy stuff.
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		#proxy_redirect off;

		# include Host header
		proxy_set_header Host $http_host;

		# proxy request to usermin server
		proxy_pass https://usermin-upstream/;
		
		# Fixes initial redirect after login
		proxy_redirect https://$host:20000/ https://$http_host/;
	}
	location / {

		# set some headers and proxy stuff.
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		#proxy_redirect off;

		# include Host header
		proxy_set_header Host $http_host;

		# proxy request to webmin server
		proxy_pass https://webmin-upstream/;
		
		# Fixes initial redirect after login
		proxy_redirect https://$host:10000/ https://$http_host/;
	}