Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Last active June 15, 2018 11:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drmmr763/747b9dc984faa58b6986 to your computer and use it in GitHub Desktop.
Save drmmr763/747b9dc984faa58b6986 to your computer and use it in GitHub Desktop.
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
Copy link

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

@fevangelou
Copy link

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
Copy link
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
Copy link

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
Copy link
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
Copy link

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

@jeffersonmidei
Copy link

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

How did you fix it, fevangelou?

@enmartinson
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
Copy link

@enmartinson Awesome, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment