Nginx Configuration File for Sendy

Sendy is a self-hosted newsletter application that lets you send trackable emails via Amazon Simple Email Service (SES) at 100x cheaper than other hosted solutions.

For Apache, it includes the .htaccess file. That’s why we don’t need any extra configuration for the Apache server.

But for Nginx, we have to configure the Nginx to run Sendy on our server. Here is the example configuration file for Sendy:

server {
    listen 80;
    listen [::]:80;

    server_name domain.com;

    autoindex off;
    index index.php index.html;

    root /srv/www/domain.com/public;
    access_log /srv/www/domain.com/logs/access.log;
    error_log /srv/www/domain.com/logs/error.log;

    location / {
        try_files $uri $uri/ $uri.php?$args;
        # Don't allow search engines to index any
        add_header X-Robots-Tag "noindex, noarchive";
    }

    location /l/ {
        rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last;
    }

    location /t/ {
        rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last;
    }

    location /w/ {
        rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last;
    }

    location /unsubscribe/ {
        rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
    }

    location /subscribe/ {
        rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last;
    }

    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;
    }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        access_log off;
        log_not_found off;
        expires 30d;
    }
}

Thank you.