Installation with NGINX

I’m trying to install Mautic on a server running NGINX 1.8. My first questions is, is version 1.8 supported? I see on their requirements it only says 1.1 with no ‘+’. That seems like a fairly old version of NGINX to be the only support version.



I unziped the files into the /var/www/mautic/ directory and tried to access it in my browser but I get a 500 error every time. I can’t find anything in the error logs, so I’m not sure why it won’t load the files.



Thanks

I’m trying to install Mautic on a server running NGINX 1.8. My first questions is, is version 1.8 supported? I see on their requirements it only says 1.1 with no ‘+’. That seems like a fairly old version of NGINX to be the only support version.

I unziped the files into the /var/www/mautic/ directory and tried to access it in my browser but I get a 500 error every time. I can’t find anything in the error logs, so I’m not sure why it won’t load the files.

Thanks

Have a go with this config

server {
    listen 80;

    root /home/mautic/public_html;
    index index.html index.htm index.php;

    error_page 404 /index.php;
        error_page 405 = $uri;

    server_name mautic.example.com;

    access_log /var/log/access_log main;
    error_log  /var/log/error_log;

    # redirect index.php to root
    rewrite ^/index.php/(.*) /$1  permanent;

    #######################################
    ##  Start Mautic Specific config #####
    #######################################

    # redirect some entire folders
    rewrite ^/(vendor|translations|build)/.* /index.php break;


    location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
        # one option: try_files $uri $uri/ /index.php$is_args$args;
        try_files $uri /index.php$is_args$args;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

    # Deny everything else in /app folder except Assets folder in bundles
    location ~ /app/bundles/.*/Assets/ {
        allow all;
    }
    location ~ /app/ { deny all; }

    # Deny everything else in /addons or /plugins folder except Assets folder in bundles
    location ~ /(addons|plugins)/.*/Assets/ {
        allow all;
    }
    #location ~ /(addons|plugins)/ { deny all; }

    # Deny all php files in themes folder
    location ~* ^/themes/(.*).php {
        deny all;
    }

    # Don't log favicon
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Don't log robots
    location = /robots.txt  {
        access_log off;
        log_not_found off;
    }

    # Deny yml, twig, markdown, init file access
    location ~* /(.*).(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
    location ~ /. {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny all grunt, composer files
    location ~* (Gruntfile|package|composer).(js|json)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;

        fastcgi_keep_conn on;
        fastcgi_pass   unix:/var/run/php-fpm/mautic.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 add_header 'Access-Control-Allow-Origin' "*";

}

You will need to modify it to match your setup though (it actually came from a link on the Slack channel, not sure who it was)

1 Like

Thanks for the reply! I tried your config and replaced everything with my information as needed, but still getting a 500 error. This is really strange and not sure what’s causing it. I might go to the Slack channel and try my luck there as well.

[quote=7945:@zpetterd]Have a go with this config

server {
    listen 80;

    root /home/mautic/public_html;
    index index.html index.htm index.php;

    error_page 404 /index.php;
        error_page 405 = $uri;

    server_name mautic.example.com;

    access_log /var/log/access_log main;
    error_log  /var/log/error_log;

    # redirect index.php to root
    rewrite ^/index.php/(.*) /$1  permanent;

    #######################################
    ##  Start Mautic Specific config #####
    #######################################

    # redirect some entire folders
    rewrite ^/(vendor|translations|build)/.* /index.php break;


    location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
        # one option: try_files $uri $uri/ /index.php$is_args$args;
        try_files $uri /index.php$is_args$args;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

    # Deny everything else in /app folder except Assets folder in bundles
    location ~ /app/bundles/.*/Assets/ {
        allow all;
    }
    location ~ /app/ { deny all; }

    # Deny everything else in /addons or /plugins folder except Assets folder in bundles
    location ~ /(addons|plugins)/.*/Assets/ {
        allow all;
    }
    #location ~ /(addons|plugins)/ { deny all; }

    # Deny all php files in themes folder
    location ~* ^/themes/(.*).php {
        deny all;
    }

    # Don't log favicon
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Don't log robots
    location = /robots.txt  {
        access_log off;
        log_not_found off;
    }

    # Deny yml, twig, markdown, init file access
    location ~* /(.*).(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
    location ~ /. {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny all grunt, composer files
    location ~* (Gruntfile|package|composer).(js|json)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;

        fastcgi_keep_conn on;
        fastcgi_pass   unix:/var/run/php-fpm/mautic.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 add_header 'Access-Control-Allow-Origin' "*";

}

You will need to modify it to match your setup though (it actually came from a link on the Slack channel, not sure who it was)[/quote]

Your config has a few issues.
Check the comments from here https://gist.github.com/that0n3guy/905c812c0f65e7ffb5ec to learn more.

Be careful with last gist, because it exposes some php file like
app/bundles/CoreBundle/Assets/js/libraries/ckeditor/filemanager/connectors/php/filemanager.php

Hello! @manyk @zpetterd and others.

Could you please post the virtualhost configuration lines that Works?

Thanks

I’ve installed a few times with nginx at various versions. Documented the steps here:

https://outergain.com/install-mautic-in-a-sub-folder-on-nginx/

Error 500 is usually related to HTTP server misconfiguration. An easy way to troubleshoot your HTTP server is to start with a very basic config file, then add parameters to it one by one.

Hello @theatereleven

Thanks for your help.

I looked at your POST and I have seein that you have added the following lines into your nginx virtual host setup file:


  1. Edit your site’s server block.

The normal path is: /etc/nginx/sites-available/yoursite.com

location /pages {
try_files $uri $uri/ /pages/?q=$uri&$args;
}

Did you only added this?

location /pages {
try_files $uri $uri/ /pages/?q=$uri&$args;
}

Is it enough to cover ALL Mautic needs to run on NGINX?
Or have you added any other lines? If so, could you please share?

Hey @Alcides,

Nginx doesn’t need any special configuring to run Mautic. There are certain PHP libraries needed, and the install will tell you if you don’t have them. The ONLY reason I had to edit my server block file is to tell nginx to allow a sub folder on my site to also host site executables. By default, your server block will tell nginx where your website files are (index.php, etc). So if you install mautic in a sub folder, nginx will not allow the index file in there to server anything up.

Hope I’m explaining that okay.

Hello @theatereleven
Thanks for your attention and help.

I understood what you Said, but based on It why people add só many lines as following?

[quote=7945:@zpetterd]Have a go with this config

server {
    listen 80;

    root /home/mautic/public_html;
    index index.html index.htm index.php;

    error_page 404 /index.php;
        error_page 405 = $uri;

    server_name mautic.example.com;

    access_log /var/log/access_log main;
    error_log  /var/log/error_log;

    # redirect index.php to root
    rewrite ^/index.php/(.*) /$1  permanent;

    #######################################
    ##  Start Mautic Specific config #####
    #######################################

    # redirect some entire folders
    rewrite ^/(vendor|translations|build)/.* /index.php break;


    location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
        # one option: try_files $uri $uri/ /index.php$is_args$args;
        try_files $uri /index.php$is_args$args;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

    # Deny everything else in /app folder except Assets folder in bundles
    location ~ /app/bundles/.*/Assets/ {
        allow all;
    }
    location ~ /app/ { deny all; }

    # Deny everything else in /addons or /plugins folder except Assets folder in bundles
    location ~ /(addons|plugins)/.*/Assets/ {
        allow all;
    }
    #location ~ /(addons|plugins)/ { deny all; }

    # Deny all php files in themes folder
    location ~* ^/themes/(.*).php {
        deny all;
    }

    # Don't log favicon
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Don't log robots
    location = /robots.txt  {
        access_log off;
        log_not_found off;
    }

    # Deny yml, twig, markdown, init file access
    location ~* /(.*).(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
    location ~ /. {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny all grunt, composer files
    location ~* (Gruntfile|package|composer).(js|json)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;

        fastcgi_keep_conn on;
        fastcgi_pass   unix:/var/run/php-fpm/mautic.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 add_header 'Access-Control-Allow-Origin' "*";

}

You will need to modify it to match your setup though (it actually came from a link on the Slack channel, not sure who it was)[/quote]

Hey @Alcides - Interesting. Looks like they’re trying to lock stuff down more? That doesn’t hurt! I’m going to try some of the above on one of my installs and see how it goes.

UPDATE: Finally added these to my config. Works! I’d recommend adding that stuff.

@theatereleven

Could you please share what you have done?

I can not make mautic running well on NGINX.

My current issue is related with CSS and JS files.
They are not beeing load.
Do you have any ideia of what is this issue?

Hey @Alcides - not sure where you’re running into problems, but here’s a blog post I did on the steps that worked for me:

https://outergain.com/install-mautic-in-a-sub-folder-on-nginx/

Hi! @theatereleven
I followed all you have done. But it is still not working.

My issue is the following error: “NetworkError: 404 Not Found - https://m.MyDomain.com/mtc.js

How to reproduce:
1 - Installed a fresh new mautic instance.
2 - setup a simple Landing Page
3 - Access the landing page.
4 - the landing page appers well but I receive the message above.

Any idea?

Check this post: https://www.mautic.org/community/index.php/4626-mtc-js-not-found/0

Hi! @theatereleven

Thanks for your help.

Yes! I have done this.

I have added:
location ~ mtc.js{
try_files $uri @phpstream;
}

With this change, I have now “500 Internal Server Error” instead of 404.

So, I am in the same mood.

We probably need to see your nginx server block file at this point.

You should have this also on another block…

location @phpstream { fastcgi_pass fastcgi_pass 127.0.0.1:9000; }

or

location @phpstream { fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #or php5.0-sock... depends on your config }

Just try and let me know if it works? I got this issue and not solve until now. See https://www.mautic.org/community/index.php/8458-form-won-t-show-via-javascrip-404-not-found/0#p26198