Get answers quicker by searching

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Nginx Rewrite Rules
  • Vote Up0Vote Down RuleroRulero
    Posts: 3Sendy user
    I noticed a few users were requesting the re-write rules for Nginx. This is something I was looking for as I use Nginx.

    I have not fully tested this, but it seems to be working fine. There is only a small issue when previewing an email campaign, this part does not render and it downloads a PHP file (I'm going to figure this out soon and get it sorted).

    Anyways, if you need this to get Sendy up and running, use the following configuration - https://gist.github.com/3928634 (I'm using PHP-FPM)

    Hope this helps.
  • 29 Comments
  • Vote Up0Vote Down almaysalmays
    Posts: 23Sendy user
    https://gist.github.com/3928668
    Is a combination of yours and mine.
    "last" directive is ok. It doesn't make a infinite loop, because every location is unique.
  • Vote Up0Vote Down almaysalmays
    Posts: 23Sendy user
    Here php gets processed correctly, because after changing uri from /foo to /foo.php it doesn't break, but goes to the php location, which doesn't rewrite any more, but sends to the php stream.
  • Vote Up0Vote Down almaysalmays
    Posts: 23Sendy user
    and when /l/ stuff get's rewriten as l.php?i=foo it doesn't go to / location, because there is an if statement, applying rewrite only if file doesn't exist, but file l.php does exist, so it passes directly to location php again.
  • Vote Up0Vote Down almaysalmays
    Posts: 23Sendy user
    Thus last not break
    cooks you a cake.
  • Vote Up0Vote Down RuleroRulero
    Posts: 3Sendy user
    @almays - I really appreciate the assistance and explanation, it certainly helps.

    I have also updated my original post with your suggestions.
  • Vote Up0Vote Down cufanocufano
    Posts: 5Sendy user
    Hello, I have used your Nginx Rewrite rules, but I can't pass from login page. When I install Sendy and go to the login page I get a download file window, but the login form don't appear.

    I have reviewed your nginx config, I have the same situation, Nginx 1.2.4 with php-fpm installed at port 9000, so the configuration must be almost identical.

    Any idea about my error?
  • Vote Up0Vote Down cufanocufano
    Posts: 5Sendy user
    Some updates:

    I have installed again Sendy and now I see login page. But when I put my credential details and press login button, the login page reloads again, I can't pass from login page...
  • Vote Up0Vote Down afavaroafavaro
    Posts: 0Sendy user
    Hey guys,

    I'm also using nginx + php-fpm with this configuration but I can't access Sendy at all - I get a 500 error every time. There are no errors reported in either the nginx or php-fpm so I'm not even sure what might be causing the error. Did you guys experience anything like this? Any tips on how I should go about debugging this?
  • I hace the dame problema, i tried the Amaya configuraciĆ³n and silla doesn't work. Pelease help.
  • Vote Up0Vote Down NlammertynNlammertyn
    Posts: 3Sendy user

    Been trying all night, but it keeps throwing a 500 error.

    Anyone willing to help?

    Here's the rules I use: http://pastebin.com/viuEJ4N1

  • Vote Up0Vote Down esusloesuslo
    Posts: 3Sendy user

    Hi guys,

    I have setup Sendy on Nginx with your help, everything works apart from Newsletter Preview, it shows 404 in that area, what could be wrong? Here is my Nginx config:

    server {
    server_name myhostname.com;
    root /var/www/myhostname.com;
    
    location = /favicon.ico {
    log_not_found off;
    access_log off;
    }
    
    location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    }
    
    location ~ /\. {
    deny all;
    }
    
    location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
    }
    
    location /sendy {
    try_files $uri $uri/ $uri.php?$args;
    }
    
    location /sendy/unsubscribe/ {
     rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
    }
    
    location /sendy/subscribe/ {
    rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last;
    }
    
    
    location / {
    try_files $uri $uri/ /index.php?$args;
    }
    
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires off;
    }
    
    location ~ \.php$ {
    try_files $uri =404;
    
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass php;
    }
    }
    
  • Vote Up0Vote Down esusloesuslo
    Posts: 3Sendy user

    Solved it, just added few more lines from the above configs.

  • @esuslo Do you mind telling me the exact code you used to fix it, I have the same issue.

  • Vote Up0Vote Down tarriointarrioin
    Posts: 4Sendy user

    mod_rewrite is not enabled

  • Vote Up0Vote Down fenixkimfenixkim
    Posts: 2Sendy user

    Hello, I'm getting a 502 Bad Gateway. Please somebody help me to fix it, these are my rules:

    server {
    
        listen 80;
    
        server_name sub.hostname.com;
    
        access_log /var/www/sub.hostname.com/logs/access.log;
        error_log /var/www/sub.hostname.com/logs/error.log;
    
        root /var/www/sub.hostname.com/public_html;
    
        index index.php index.html;
    
        location / {
            index index.php;
    
            if (!-f $request_filename){
                    rewrite ^/([a-zA-Z0-9-]+)$ /$1.php last;
            }
        }
    
        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 ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
            expires max;
            log_not_found off;
        }
    
        location ~ \.php$ {
            try_files $uri =404;
    
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
    }
    
  • Vote Up0Vote Down fenixkimfenixkim
    Posts: 2Sendy user

    Hey, I have added:

    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    

    to the nginx.conf, and the 502 message no longer appears, but now I'm having a blank screen in the _install.php page, Any idea?

    update

    The error.log is show me:

    2013/08/17 17:06:55 [error] 12801#0: *13 FastCGI sent in stderr: "PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 7
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 22
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 33
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 44
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 55
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 66
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 77
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 89
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 102
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 114
    PHP message: PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/sub.hostname.com/public_html/includes/update.php on line 126
    PHP messag
    

    And the access.log:

    200.122.212.41 - - [17/Aug/2013:17:05:20 -0500] "GET / HTTP/1.1" 302 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1"
    200.122.212.41 - - [17/Aug/2013:17:05:22 -0500] "GET /_install.php HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1"
    200.122.212.41 - - [17/Aug/2013:17:06:55 -0500] "GET /_install.php HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1"
    
  • Hey everyone,

    I just made the switch to Nginx and PHP-FPM and I've written this Nginx server configuration for Sendy. It's been working well for me and I'm using the latest version of Sendy (v1.1.7.7).

    https://gist.github.com/refringe/6545132

    Just be sure those log files exist, and Nginx's "www-data" group has read/write permissions.

    Let me know if you run into any issues.
    All the best!

  • Can anyone paste their latest working nginx config? I am trying to get it to work on Heroku, I cant seem to get past the invalid domain problem.

  • Vote Up0Vote Down ericzooericzoo
    Posts: 1Sendy user

    agree with danielmahon. any new ones? mine seem to cause loops on installation

  • Vote Up0Vote Down brownellbrownell
    Posts: 4Sendy user

    Have you tried my config above? It's working for me as of version 1.1.9.4.

  • Vote Up0Vote Down seddassseddass
    Posts: 1Sendy user

    Same with danielmahon and ericzoo.. mine seem to cause loops on installation when trying the brownell nginx config.

  • Hi, I've managed to set up a mySQL database, modify the config.php file, upload the sendy files to the server, and set up a AWS account. The part where I am stuck is.... where do I put the re-write rules for Nginx? I know I'm suppose to use the code on github but I don't know what to do with it. I've tried to find a simple tutorial but have had no luck. Any help for this noob would be appreciated.

    Also... the site is hosted by Digital Ocean and I'm using Server Pilot as the control panel. Thanks!!

  • I know this thread is old, but I have nowhere else to ask for relevant answers.

    I installed Sendy in my website's /sendy subdirectory. I've tried multiple Nginx configurations posted here previously, however none of them worked.

    I have Nginx & PHP-FPM.

  • Vote Up0Vote Down edtaaedtaa
    Posts: 1Sendy user

    Although this thread seems to have died I did find it very useful to get Sendy running on Nginx. However, I can't get translation working with my set up - Debian / Nginx / Sendy. Well, I can do it by forcing the translation through editing /includes/helper/locale.php but changing core files is, of course, a no no.

  • Vote Up0Vote Down brucehbruceh
    Posts: 1Sendy user

    I've just purchased and installed Sendy on a subdomain on my DigitalOcean machine running NGINX (1.4.6 ubuntu) and this seem to be working pretty well.

    Its based on suggestions from https://gist.github.com/refringe/6545132

    and modified to handle PHP 7

    I hope it helps somebody.

    Bruce

    server {
        listen 80;
        listen [::]:80;
    
        server_name sendy.mydomain.com;
    
        autoindex off;
        index index.php index.html;
    
        root /websites/mydomian/www/sendy/;
    
        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 ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
            access_log off;
            log_not_found off;
            expires 30d;
        }
    
            location ~ \.php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
            }
    }
    
  • Hi guys idk but just telling, try to disable Varnish Cache if you got some logout problems

  • Vote Up0Vote Down mqudsimqudsi
    Posts: 3Sendy user

    Hello all,

    Just wanted to share the rules I am using for sendy on nginx, because I found several online that were blatantly incorrect (not just out of date):

        location /sendy {
                access_log off;
                error_log off;
                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;
        }
    

    You can replace /sendy with / if you run it out of the root of a (sub)domain.

  • Vote Up0Vote Down enchanterenchanter
    Posts: 7Sendy user

    Hi. I managed to set an nginx redirect doing the following: I changes nginx.conf (root/etc/nginx/nginx.conf) and added the following change:

    http {

    server { server_name .green.net; return 301 https://www.green.com$request_uri; }

    Which works fine but redirects not only the root domain (green.net > green.com), but also would redirect a link like green.net/one/two/three/four > green.com/one/two/three/four

    but here comes the difficult part i want to keep all redirects described above and at the same time i want to be able to redirect a subdomain - one.green.net/monday/tue/wen-4 > one.green.info/monday/tue/wen-4

    Here is the last i tried, which does NOT work. If s.o. knows what is wrong with that one below, that would definitely be the high line of the month. http {

    server { server_name .green.net;

    #if ($request_uri ~ monday) {
        #return 301 https://one.green.info$request_uri; 
    #} else {
        return 301 https://www.green.com$request_uri;
    #}
    

    }

  • Vote Up0Vote Down deltahfdeltahf
    Posts: 2Sendy user

    Just wanted to say thanks for sharing your configuration, @mqudsi. It is working for me, and that is clearly the simplest way compared to the rest of the advice out there.

    I am surprised there is no official documentation with Sendy on this, considering how popular Nginx is.