NGINX Configuration for Sendy

NGINX Configuration for Sendy

Having recently migrated from Apache 2 to NGINX (with PHP-FPM) for a site that included Sendy, I thought it would be worth posting the configuration required in order for it to work.

Sendy natively has an .htaccess file and some simple rules in order for it to work correctly. I came across some other configurations via Google but most seemed overly complicated.

You will need to tweak:

  • The domain name used for your configuration
  • The base directory used
  • The PHP-FPM UNIX socket path, or replace it your TCP/IP settings
	# Domain name of this example config
	# Listening on port 80
	listen 80;
	# Base directory of public website
	root /home/www/;
	# Which filenames are treated are indexes of a directory
	index index.php index.html;
	fastcgi_index index.php;
	# Logging files
	error_log  /home/logging/  debug;
	access_log  /home/logging/;
    # Compact way of dealing with all extensionless URLs that use the URL path as a GET variable
    location ~ /sendy/(l|t|w|(un)?subscribe)/ {
        rewrite ^/sendy/([^/]+)/([a-zA-Z0-9/]+)$ /sendy/$1.php?i=$2 last;
	# Sendy specific internal rewrites. Sendy URLs are extensionless, this rule matches extensionless URLs and appends the .php extension
	location /sendy/ {
		rewrite ^/sendy/([a-zA-Z0-9\-]+) /sendy/$1.php?$args last;
	# Cache static data and prevent logging of non-existent static assets
	location ~* \.(ico|css|js|gif|jpe?g|png|woff|ttf)(\?[0-9]+)?$ {
		expires max;
		log_not_found off;
	# Default PHP configuration
	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		# Here I am using a UNIX socket to connect to PHP
		fastcgi_pass unix:/home/;
		fastcgi_index index.php;
		include fastcgi_params;
		keepalive_timeout 0;
		fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name;
		fastcgi_param DOCUMENT_ROOT /;

Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.