Add additional vhost to nginx

I want to configure nginx with an additional vhost.

I added an A-record for a subdomain to the DNS configuration. The IP is equal to the box’ IP. Then I added a file example.conf to /etc/nginx/sites-enabled with content:

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

        server_name example.mydomain.net;

        return 200 'gangnam style!';
}

However, when I try to visit example.mydomain.net, I get redirected to Roundcube. Only when I uncomment include /etc/nginx/conf.d/*.conf; in nginx.conf (so not include the configuration generated by MIAB) does the vhost work properly.

Does anyone know why this is? Or how to get it to work while still including the MIAB nginx configuration?

You do not configure Nginx in this manner with MiaB. So undo everything that you have done. Everything.

Now, add a user or alias with an email address in the format of user@example.mydomain.net
Then go to the web tab in the admin area, where your sub-domain is listed, click on the ‘change’ box. Follow the instructions by adding the new directory on the server, then click the update button.
Viola! Done.

I want to use nginx as a reverse proxy for something, not as a file server.

I found out about an undocumented feature that allows me to do this with a YAML file.

Still, I wonder why adding another server block to a file in /etc/nginx/sites-enabled doesn’t work!

I explained that in the previous response.

My question was why nginx doesn’t pick up that configuration file.

Because Nginx is configured to pick up the server blocks in a different location in MiaB. I will look later to see exactly where the location is, but do not have time atm.

Are you sure? /etc/nginx/nginx.conf:

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

It should process both locations. In fact, when I uncomment the first line, the additional vhost does work. So I wonder what is in the conf.d that prevents the configuration files in sites-enabled to be processed.