Virtualmin nginx alias


I am trying to set up alias for my domains the thing is:

Main domain: -> root for this is home/domain/


Nginx config of aliases:

server {
root /home/domain/public_html;
index index.html index.htm index.php;
access_log /var/log/virtualmin/domain.de_access_log;
error_log /var/log/virtualmin/domain.de_error_log;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME /home/domain/public_html$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /home/domain/public_html;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass unix:/var/php-nginx/15161112352697.sock/socket;
        fastcgi_pass unix:/var/php-nginx/14892222483561.sock/socket; -> this is same as defined in
listen ssl;
ssl_certificate /home/;
ssl_certificate_key /home/;

I want to know if it is good solution or if there is any other way to do this



Ok I gave up on this solution. I added it as an alias. But I have problem with ssl redirect. I have this rule in the config:

if ($scheme != "https") {
        rewrite ^$uri permanent;

How can I change .eu to the current server????

I got it working with this but I need to remove www. From $host

if ($scheme != "https") {
        rewrite ^ https://$host$uri permanent;

Have you tried to set to YES this:

Webmin=>Servers=>Virtualmin Virtual Servers=> SSL Settings=>Redirect HTTP to HTTPS by default?

instead of put a redirect inside every vhost configuration?

Hello the Domain alias created w/ Virtualmin gives a 404 Not Found on nginx/1.14.2 I did give a Yes to Webmin=>Servers=>Virtualmin Virtual Servers=> SSL Settings=>Redirect HTTP to HTTPS by default. But still Alias domain gives a 404… ;-( Any idea ? Thanks.

Ilia's picture
Submitted by Ilia on Fri, 01/31/2020 - 16:07

I did give a Yes to Webmin=>Servers=>Virtualmin Virtual Servers=> SSL Settings=>Redirect HTTP to HTTPS by default. But still Alias domain gives a 404… ;-( Any idea ? Thanks.

This will only be applied to the newly created virtual servers (domains).

You can manually create redirect at Server Configuration/Website Redirects. You can have a look at the screenshot to check an example of how it's done.

Hello Ilia, Thank you for your message and your concern.

So, yes I found a "Server Configuration/Website Redirects" but only for the main Server (with a tutorial, but there is not such a setting for the Alias Server. I must indicate that the Alias Server had been created as an Alias of the main Server. I used to do that frequently in Virtualmin but in the Apache setting. That was done easily from the drop-down box on the top-left. As I moved the server from Apache to Nginx I encountered this issue. In the /etc/nginx/sites-available/MAIN-DOMAIN.conf there is the indication of the Alias Server :


Looking further I found that the access to http://ALIAS-DOMAIN/ gives a 404 error. Then the https://ALIAS-DOMAIN gives a warning because it uses a certificate that is not valid for ALIAS-DOMAIN. The certificate is only valid for MAIN-DOMAIN.

That might means that the issue is the refusal of the setting of the ALIAS-DOMAIN by certbot : sudo sudo certbot certonly --nginx gives

   Type:   unauthorized
   Detail: Invalid response from
   [DOMAIN-IP]: "<html>\r\n<head><title>404 Not
   Found</title></head>\r\n<body bgcolor="white">\r\n<center><h1>404
   Not Found</h1></center>\r\n<hr><center>"

So the issue is more pinpointed in the https setting.

EDIT : I found the reason and the solution of the issue. After using certbot certificate installation, there is a change made in the /etc/nginx/sites-available/MAIN-DOMAIN.conf Then after adding the ALIAS-DOMAIN via Webmin, certbot cannot add the change in the MAIN-DOMAIN.conf. The solution was to add manually in the MAIN-DOMAIN.conf :

    if ($host = ALIAS-DOMAIN) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

Then certbot certificate renewal can be run for both MAIN-DOMAIN and ALIAS-DOMAIN. SOLVED