Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx configuration file example for Sendy (http://sendy.co/).
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;
}
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;
}
}
@fabiopili

This comment has been minimized.

Show comment
Hide comment
@fabiopili

fabiopili Mar 31, 2015

It'd be a good idea to add:

# Don't allow search engines to index any 
add_header X-Robots-Tag "noindex, noarchive";

before the first location / line to avoid search engines indexing the Sendy login page.

fabiopili commented Mar 31, 2015

It'd be a good idea to add:

# Don't allow search engines to index any 
add_header X-Robots-Tag "noindex, noarchive";

before the first location / line to avoid search engines indexing the Sendy login page.

@kalelc

This comment has been minimized.

Show comment
Hide comment
@kalelc

kalelc Mar 2, 2016

Hello, I have Nginx 1.4.6 with Sendy 2.0.7. With this configuration i get mod_rewrite is not enabled

kalelc commented Mar 2, 2016

Hello, I have Nginx 1.4.6 with Sendy 2.0.7. With this configuration i get mod_rewrite is not enabled

@sergeifilippov

This comment has been minimized.

Show comment
Hide comment
@sergeifilippov

sergeifilippov Mar 3, 2016

@kalelc php does is not able to detect mod_rewrite like functionality in nginx properly so it'll always say that but will continue working fine.

sergeifilippov commented Mar 3, 2016

@kalelc php does is not able to detect mod_rewrite like functionality in nginx properly so it'll always say that but will continue working fine.

@viet

This comment has been minimized.

Show comment
Hide comment
@viet

viet Apr 2, 2016

It's not really working for me. :\

viet commented Apr 2, 2016

It's not really working for me. :\

@dillonbailey

This comment has been minimized.

Show comment
Hide comment
@dillonbailey

dillonbailey Apr 9, 2016

@viet also not working for me, I've tried to start another thread with the Sendy admin...will see how we go.

dillonbailey commented Apr 9, 2016

@viet also not working for me, I've tried to start another thread with the Sendy admin...will see how we go.

@makecontact

This comment has been minimized.

Show comment
Hide comment
@makecontact

makecontact Apr 21, 2016

Config works fine for me.

Incase you missed it remember to change the paths of the rewrite rules relative to your install e.g.

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

Might be:

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

Note THREE places where you must add the full path.

To be honest, I didn't want to risk this incase there are some direct links in emails and sendy's backend to worry about so I just installed it in the root folder - in which case the above config works fine.

makecontact commented Apr 21, 2016

Config works fine for me.

Incase you missed it remember to change the paths of the rewrite rules relative to your install e.g.

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

Might be:

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

Note THREE places where you must add the full path.

To be honest, I didn't want to risk this incase there are some direct links in emails and sendy's backend to worry about so I just installed it in the root folder - in which case the above config works fine.

@viettd

This comment has been minimized.

Show comment
Hide comment
@viettd

viettd Jul 20, 2016

@viet, @dillonbailey I edit some config and it work for me:

location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
 }

Hope that work for you too.

P/S: I install sendy in subdomain.

viettd commented Jul 20, 2016

@viet, @dillonbailey I edit some config and it work for me:

location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
 }

Hope that work for you too.

P/S: I install sendy in subdomain.

@ahmadawais

This comment has been minimized.

Show comment
Hide comment
@ahmadawais

ahmadawais Mar 17, 2017

It is hacky but works though it is not parsing the URLs. I cannot parse domain.tld/login and instead have to add domain.tld/login.php

ahmadawais commented Mar 17, 2017

It is hacky but works though it is not parsing the URLs. I cannot parse domain.tld/login and instead have to add domain.tld/login.php

@ahmadawais

This comment has been minimized.

Show comment
Hide comment
@ahmadawais

ahmadawais Mar 17, 2017

This worked for me, make sure there are no other rules duplication or overlap

 location / {
         try_files $uri $uri/ $uri.php?$args;
     }
     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 php:9000;
     #     fastcgi_index index.php;
     #     include fastcgi_params;
     #     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     #     fastcgi_param PATH_INFO $fastcgi_path_info;
     # }

     location ~ \.php$ {
             try_files $uri =404;
             fastcgi_split_path_info ^(.+\.php)(/.+)$;
             fastcgi_pass 127.0.0.1:9000;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include fastcgi_params;
      }

ahmadawais commented Mar 17, 2017

This worked for me, make sure there are no other rules duplication or overlap

 location / {
         try_files $uri $uri/ $uri.php?$args;
     }
     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 php:9000;
     #     fastcgi_index index.php;
     #     include fastcgi_params;
     #     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     #     fastcgi_param PATH_INFO $fastcgi_path_info;
     # }

     location ~ \.php$ {
             try_files $uri =404;
             fastcgi_split_path_info ^(.+\.php)(/.+)$;
             fastcgi_pass 127.0.0.1:9000;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include fastcgi_params;
      }

@martingrega

This comment has been minimized.

Show comment
Hide comment
@martingrega

martingrega Oct 25, 2017

Hey,
there is a bug in the config. You forgot to escape second dot.
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
should be
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|xml)$ {

Our randomly generated tracking link ended with characters "pNg" and all links in newsletter stopped working.

martingrega commented Oct 25, 2017

Hey,
there is a bug in the config. You forgot to escape second dot.
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
should be
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|xml)$ {

Our randomly generated tracking link ended with characters "pNg" and all links in newsletter stopped working.

@mj6uc

This comment has been minimized.

Show comment
Hide comment
@mj6uc

mj6uc Nov 7, 2017

Thanks @perceptiveIO, your observation saved the day! :-)

mj6uc commented Nov 7, 2017

Thanks @perceptiveIO, your observation saved the day! :-)

@codegeek1001

This comment has been minimized.

Show comment
Hide comment
@codegeek1001

codegeek1001 Nov 29, 2017

For me, this one worked for prettifying urls

 location / {
        try_files $uri $uri/ /$uri.php?is_args$args;
}

codegeek1001 commented Nov 29, 2017

For me, this one worked for prettifying urls

 location / {
        try_files $uri $uri/ /$uri.php?is_args$args;
}
@Lemmings19

This comment has been minimized.

Show comment
Hide comment
@Lemmings19

Lemmings19 Jul 11, 2018

Installing Sendy at https://mydomain.com/sendy, this worked for me:

    location /sendy {
        rewrite ^/sendy/(l|t|w)/([a-zA-Z0-9\/]+)$ /sendy/$1.php?i=$2&$args;
        rewrite ^/sendy/(u?n?subscribe)/(.*)$ /sendy/$1.php?i=$2&$args;
        try_files $uri $uri/ $uri.php?$args;

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

If you're having issues, check https://mydomain.com//sendy/_compatibility.php?i=1 to see if anything isn't configured properly. mod_rewrite is not enabled will probably always show up if you're using Nginx.

Lemmings19 commented Jul 11, 2018

Installing Sendy at https://mydomain.com/sendy, this worked for me:

    location /sendy {
        rewrite ^/sendy/(l|t|w)/([a-zA-Z0-9\/]+)$ /sendy/$1.php?i=$2&$args;
        rewrite ^/sendy/(u?n?subscribe)/(.*)$ /sendy/$1.php?i=$2&$args;
        try_files $uri $uri/ $uri.php?$args;

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

If you're having issues, check https://mydomain.com//sendy/_compatibility.php?i=1 to see if anything isn't configured properly. mod_rewrite is not enabled will probably always show up if you're using Nginx.

@ttk

This comment has been minimized.

Show comment
Hide comment
@ttk

ttk Aug 2, 2018

There is a bug on line 46 of the example code, the period needs to be escaped...

Should be:

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

ttk commented Aug 2, 2018

There is a bug on line 46 of the example code, the period needs to be escaped...

Should be:

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

This comment has been minimized.

Show comment
Hide comment
@gnif

gnif Sep 23, 2018

All these rewrites could be simplified to a single location match and rewrite like so:

location ~ ^\/(l|t|w|(un)?subscribe)\/ {
  rewrite ^\/([^/]+)\/(.+)$ "/$1.php?i=$2" last;
}

gnif commented Sep 23, 2018

All these rewrites could be simplified to a single location match and rewrite like so:

location ~ ^\/(l|t|w|(un)?subscribe)\/ {
  rewrite ^\/([^/]+)\/(.+)$ "/$1.php?i=$2" last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment