Skip to content

Instantly share code, notes, and snippets.

@drmmr763 drmmr763/default
Last active Jun 15, 2018

Embed
What would you like to do?
mautic-symfony-nginx
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name _;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on /tmp/php5-fpm.sock
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
### phpMyAdmin ###
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
client_max_body_size 4M;
client_body_buffer_size 128k;
try_files $uri =404;
root /usr/share/;
# Point it to the fpm socket;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)) {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
### phpMyAdmin ###
}
@that0n3guy

This comment has been minimized.

Copy link

that0n3guy commented Sep 11, 2015

Just throwing this link in here, but this is a more complete and secure config:
https://gist.github.com/that0n3guy/905c812c0f65e7ffb5ec

@fevangelou

This comment has been minimized.

Copy link

fevangelou commented Dec 4, 2015

Guys, neither config works with the mtracking.gif rewrite btw...

@that0n3guy you set the root path at /app then a little lower you deny all access to it. Wow.
@drmmr763 Your "index" does not even include index.php so parsing would probably fail from the start. The phpMyAdmin block is not really needed to showcase Mautic on Nginx, right?

@drmmr763

This comment has been minimized.

Copy link
Owner Author

drmmr763 commented Dec 4, 2015

Somehow it worked for me or it seemed to when I did this; but it was quite a long time ago.

You might have better luck referring to Symfony's documentation these days:
http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

If you're able to get it to working feel free to share what you came up with!

@fevangelou

This comment has been minimized.

Copy link

fevangelou commented Dec 4, 2015

The Symfony guides refer to the way an app is proposed to be built with Symfony. The /app folder is what's public and everything else is hidden from the public. Which is a bit different to how Mautic is built for my understanding. I didn't have issues making the app work with URL rewriting, it's far easier than you think. The problem is the tracking endpoint. And the weird thing is that Mautic chose to use a .gif endpoint to do php stuff. This confuses the web server, unless there's a rewrite pattern. Looking at the .htaccess file, I don't see such a rewrite rule specifically for mtracking.gif.

@drmmr763

This comment has been minimized.

Copy link
Owner Author

drmmr763 commented Dec 4, 2015

I think the only difference between them is Mautic uses index.php to init the application instead of app.php. Could be wrong, but that was my understanding when I did this originally.

mtracking.gif is a route defined in Symfony, and I think that as long as all the requests are pushed through index.php, then symfony should handle the proper response. But now that you mention it I don't remember ever testing mtracking.gif calls, I probably only tested using Mautic the app. So you might be right there.

Did you get Mautic's app to work on nginx? are you getting errors with mtracking?

@fevangelou

This comment has been minimized.

Copy link

fevangelou commented Dec 4, 2015

404 not found with mtracking.gif only. Everything else works.

@jeffersonmidei

This comment has been minimized.

Copy link

jeffersonmidei commented Jun 23, 2016

404 not found with mtracking.gif only. Everything else works.

How did you fix it, fevangelou?

@enmartinson

This comment has been minimized.

Copy link

enmartinson commented Aug 23, 2016

I was able to solve this by putting two lines in the server config:

location ~ mtc.js{
    try_files $uri /index.php?$args;
}
location ~ mtracking.gif{
      try_files $uri /index.php?$args;
}

Once that was in and I reloaded nginx it started working for me...

@droidlabour

This comment has been minimized.

Copy link

droidlabour commented Jun 15, 2018

@enmartinson Awesome, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.