VestaCP: Nginx Template For Mailwizz

VestaCP: Nginx Template For Mailwizz

Last updated: 22 April 2022

This is VestaCP Nginx template for Mailwizz autoresponder. To use this template, I assume that you are using pretty url.

We need to create 2 files in VestaCP template directory. One file is for normal http connection and the other one is for secure https connection.

Http connection will use .tpl for configuration. And https connection will use .stpl for configuration.

Create 2 file in directory below.

Template Directory

/usr/local/vesta/data/templates/web/nginx/php-fpm

You can use any name for your template. In my case, I used mailwizz.

Code snippet for .stpl

server {
    listen      %ip%:%web_ssl_port%;
    server_name %domain_idn% %alias_idn%;
    root        %sdocroot%;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/%domain%.log combined;
    access_log  /var/log/nginx/domains/%domain%.bytes bytes;
    error_log   /var/log/nginx/domains/%domain%.error.log error;

    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;

    location / {

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }
        
        if (!-e $request_filename){
            rewrite ^(/)?api/.*$ /api/index.php;
        }
        if (!-e $request_filename){
            rewrite ^(/)?customer/.*$ /customer/index.php;
        }
        if (!-e $request_filename){
            rewrite ^(/)?backend/.*$ /backend/index.php;
        }
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php;
        }
        
        index  index.html index.htm index.php;

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    %backend_lsnr%;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    location /vstats/ {
        alias   %home%/%user%/web/%domain%/stats/;
        include %home%/%user%/conf/web/%domain%.auth*;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     %home%/%user%/conf/web/snginx.%domain%.conf*;
}

Code snippet for .tpl

server {
    listen      %ip%:%web_port%;
    server_name %domain_idn% %alias_idn%;
    root        %sdocroot%;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/%domain%.log combined;
    access_log  /var/log/nginx/domains/%domain%.bytes bytes;
    error_log   /var/log/nginx/domains/%domain%.error.log error;

    location / {

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }
        
        if (!-e $request_filename){
            rewrite ^(/)?api/.*$ /api/index.php;
        }
        if (!-e $request_filename){
            rewrite ^(/)?customer/.*$ /customer/index.php;
        }
        if (!-e $request_filename){
            rewrite ^(/)?backend/.*$ /backend/index.php;
        }
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php;
        }
        
        index  index.html index.htm index.php;

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    %backend_lsnr%;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    location /vstats/ {
        alias   %home%/%user%/web/%domain%/stats/;
        include %home%/%user%/conf/web/%domain%.auth*;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     %home%/%user%/conf/web/snginx.%domain%.conf*;
}

Github File

  • You may download the files directly from my GitHub repository HERE

That pretty much it for the template part.

After that you can change your Nginx web template in your VestaCP control panel. Don't forget to restart nginx web server.

If you are having WordPress inconsistent file permission error, you might want to check my previous post.

I hope this will help someone.