Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GS and NGINX
#1
i'm using GetSimple with nginx and it's really fast. I tried to create a good config file, hope someone will improve this. At the moment i'm running 8 low traffic sites on a low end VPS using less than 100 MB ram, including exim4, php, and all modules i loaded. And all perform well even under heavy simulated traffic (loadimpact.com test).

My guess it that GetSimple CMS and Nginx together are the best and fastest thing you can use if you want a lot of speed on a budget server.

Code:
server {
        listen 80;
        server_name mysite.org;
        charset utf-8;
        access_log off;
        root /var/www/mysite.org;
        index index.php;
        
        location / {
            try_files       $uri $uri/ /index.php?id=$uri&$args;
        }

       location ~* /admin/.*\.php$ {
            try_files $uri /admin/index.php?id=$uri&$args;
            include /etc/nginx/fastcgi_params;
            fastcgi_index index.php;
            fastcgi_pass unix:/var/run/www/php.sock;
       }        
        
        location ~* \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_index index.php;
            try_files $uri =404;
            fastcgi_pass unix:/var/run/www/php.sock;
            expires 2h;
        }

        location ~* \.(?:ico|js|gif|jpg|png)$ {
            expires 14d;
        }

        location ~* \.(htm|css|html)$ {
            expires 2d;
        }

# this blocks direct access to the XML files (but sitemap.xml) - that hold all the data
        location ~* \.xml$           { deny all; }
    location ~* \.xml\.bak$     { deny all; }
        location = /sitemap.xml { allow all; }

# this prevents hidden files (beginning with a period) from being served
        location ~ /\.          { deny all; }

        location ^~ /uploads/ {
        if ($request_uri ~* \.php$) {return 403;}
        }
}

a more advanced config is available here: http://get-simple.info/forums/showthread...0#pid24930
(updated jan 2013 - better security and works with GS v.3.2)
Reply
#2
Hi Marrco,

I am new to both GetSimple and to configuring Nginx (I have been using it for several months now following the basic setup found at http://library.linode.com )

I like your use of the try_files directive, which is very efficient if the entire site is based on GS. Instead of that approach I ported the Apache rewrite rules to:

Code:
if (!-e $request_filename){
              rewrite ^(/[A-Za-z0-9\-]+)?/([A-Za-z0-9\-]+)/?$ /index.php?id=$2 last;
            }

Here
Code:
^(/[A-Za-z0-9\-]+)?
matches the parent page if any, and
Code:
/?$
supports slugs with or without a trailing / . I didn't want a regexp in the rewrite rule so general that it would match content in other (non-GetSimple) subdirectories on the site, including DokuWiki.

I agree with all your positive comments about Nginx. When I am more comfortable with its configuration files I'll migrate all my sites (hosted on various inexpensive VPSs) to it. I have been using Cherokee but had some problems with version upgrades and decided the user-friendly management interface wasn't worth it.

Regards,
Bill
Reply
#3
Hi BillF,
try_files is more efficient, one more reason to chose nginx over apache, but it is not supported on old builds.

I think my config has 2 problems:
-) still missing newer .htaccess rules (i think there's something to deny access to xml files but /sitemap.xml and maybe a few others)
-) 404 for mysite.com/notexistent.php

so i'm waiting to test 3.0 final to add the newer rules and post this as a WIKI.

i think nginx is the best companion for a light and fast cms like GetSimple
Reply
#4
I'm using this code

Code:
location / {
                try_files $uri $uri/ /index.php?id=$uri;
        }

and it works well with the %slug% structure. if I use %parent/%slug% it throws me a 404 error for all child pages.

Any ideas? Thanks.
Reply
#5
here a slightly better version. Includes fastcgi caching and more security.
Code:
... removed because of a few bugs, a better version is is posted below ...
Reply
#6
Hello marrco, thanks for posting that pesky configuration!

There is , however, a slight problem with it: it does not serve the javascripts for the admin section.
I get an "access denied" message ...

What I did was to copy the exact config file as you posted it, modify the server name and also replace the line
Code:
fastcgi_pass unix:/var/run/www/php.sock;
with
Code:
fastcgi_pass   127.0.0.1:9000;
since I use php 5 fmp modules.

Would you have an idea of what's wrong here?

Thanks in advance!
Reply
#7
@softexpert, i just updated that config (it was missing an explicit allow for sitemap.xml) but it should work fine. No idea about your error. Try to comment out the fcgi cache part, or start testing with the first config i posted (mind that's insecure!). Most options i'm using are for NGINX version 1 or newer with php 5.3.x and have been tested only on debian squeeze with nginx installed via backports (that's adding to your
Code:
/etc/apt/sources.list
a line with
Code:
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free
and (re)installing nginx via
Code:
apt-get -t squeeze-backports install nginx
)
what's the exact error you're receiving?
Reply
#8
@marrco

Since you seem to have tinkered with the nginx setup quite a lot, would you know what the rewrite
rules are for the News Manager Plugin http://get-simple.info/extend/plugin/news-manager/43/

The bits that need to be converted to nginx are:

Code:
RewriteRule ^news/tag/([^/.]+)/?$ index.php?id=news&tag=$1 [L]
RewriteRule ^news/post/([^/.]+)/?$ index.php?id=news&post=$1 [L]
RewriteRule ^news/page/([^/.]+)/?$ index.php?id=news&page=$1 [L]
RewriteRule ^news/archive/([^/.]+)/?$ index.php?id=news&archive=$1 [L]

Ideally, I would like the rules to be flexible enough to adapt to any path, as in changing
from 'news' to 'blog' without redoing the whole rewrite. But any option will do, really.

Sorry for hijacking this thread, but I didn't want to start a new one since it's the same subject.
Reply
#9
nginx ADVANCED config. Trying to do better caching and trying to detect logged-in users. I also have a nginx reverse proxy config ready, to use it in front of apache, but i prefer to stick with this first. Pls notice that this config is not yet officially supported so use at your own risk. pls review and share your suggests. I've implemented 2 caching strategies: server side fast_cgi microcaching (10seconds) and client side expires set to 2hrs for pages.
Before dealing with caching and other advanced settings do read the NGINX admin guide here: http://nginx.com/resources/admin-guide/

Code:
## define here or in /etc/nginx/nginx.conf if you have multiple sites sharing the same cache
fastcgi_cache_path  /var/cache/nginx  levels=1:2 keys_zone=GETSIMPLE:10m inactive=15m;
##
                
map $http_cookie $logged_in {
    default 0;
    ~GS_ADMIN_USERNAME 1; # This will return true if user is logged in
}

server {
  listen          80;
  server_name     *.mysite.org *.mysite.com;
  return             301 http://mysite.org$request_uri;
}

server {
        listen 80;
        server_name mysite.org;
        charset utf-8;
        access_log off;
        root /var/www/mysite.org;
        index index.php;
        
        location / {
            try_files       $uri $uri/ /index.php?id=$uri&$args;
            fastcgi_cache_bypass $logged_in;
           fastcgi_no_cache $logged_in;
        }

       location ~* /admin/.*\.php$ {
            try_files $uri /admin/index.php?id=$uri&$args;
            include /etc/nginx/fastcgi_params;
            fastcgi_cache_bypass $logged_in;
            fastcgi_no_cache $logged_in;
            fastcgi_index index.php;
            fastcgi_pass unix:/var/run/www/php.sock;
       }        
        
        location ~* \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_index index.php;
            try_files $uri =404;
            fastcgi_cache_bypass $logged_in;
            fastcgi_no_cache $logged_in;
            fastcgi_pass unix:/var/run/www/php.sock;
            fastcgi_cache GETSIMPLE;
            fastcgi_cache_key "$scheme$request_method$host$request_uri";
            fastcgi_cache_valid  200 302  10s;
            fastcgi_cache_valid  404      2m;
            expires 2h;
        }

        location ~* \.(?:ico|js|gif|jpg|png)$ {
            expires 14d;
        }

        location ~* \.(htm|css|html)$ {
            expires 2d;
        }

# this blocks direct access to the XML files (but sitemap.xml) - that hold all the data
        location ~* \.xml$           { deny all; }
        location ~* \.xml\.bak$     { deny all; }
        location = /sitemap.xml { allow all; }

# this prevents hidden files (beginning with a period) from being served
        location ~ /\.          { deny all; }

        location ^~ /uploads/ {
        if ($request_uri ~* \.php$) {return 403;}
        }
}

(updated Apr. 2014, and tested with GS 3.3.1)
Reply
#10
Many thanks to @marcco for sharing this nginx confs, i'm using it with success! I only made 2 small additions: first one to block access to log files (location ~* \.log$ { deny all; }) and the second one are the rewrites for the news manager plugin, so @incognito can test it also:


## rewrites for news manager
rewrite ^/news/post/([^/.]+)/?$ /index.php?id=news&post=$1 last;
rewrite ^/news/tag/([^/.]+)/?$ /index.php?id=news&tag=$1 last;
rewrite ^/news/page/([^/.]+)/?$ /index.php?id=news&page=$1 last;
rewrite ^/news/archive/([^/.]+)/?$ /index.php?id=news&archive=$1 last;
Reply
#11
Hi all,

The code published by marrco at the first post is not displaying the parents pages.

It shows: www.mysite.com/sub-article/
While it should show: www.mysite.com/article/sub-article/

Can anybody help me fixing this?
Reply
#12
Have you set a permalink structure in admin -> settings?
Reply
#13
Yes, if I set " %parent%/%slug%/ " it works fine with two levels of articles.
Code:
Example: http://www.mysite.com/article/sub-article/

But it doesn´t work with more leves of articles
Code:
Example: http://www.mysite.com/article/sub-article/sub-sub-article

Any idea of how to fix it?
Reply
#14
GS allows to have a multilevel page structure, but currently supports a maximum of 2 levels in URLs.

Some time ago I posted a patch to allow a 3rd level, but requires modifying some GS core file.
Reply
#15
Ok, thanks for your help Smile
Reply
#16
Hi marrco,

Thank you for sharing this nginx site config with us...

I have tried using it on my low end box and am running into some issues. I get a "redirect loop" error when trying to install

Changing your admin folder try_files from:
Code:
location ~* /admin/.*\.php$ {
            try_files $uri /admin/index.php?id=$uri&$args;
...
}
to
Code:
location ~* /admin/(.*)\.php$ {
            try_files $uri /admin/$1.php?id=$uri&$args;
...
}

Allows me to view the first two pages of the installation procedure, but the URL is strange: example.com/index.php/admin/install.php - Is that right?

Then, after inputting the website details and continuing, I get this server error:
Code:
2013/03/07 15:03:46 [error] 26454#0: *20 rewrite or internal redirection cycle while internally redirecting to "/admin/setup.php/admin/setup.php", client: 81.138.127.89, server: example.com, request: "POST /admin/setup.php/admin/setup.php HTTP/1.1", host: "example.com", referrer: "http://example.com/index.php/admin/setup.php"

I'm confused, I think that the admin folder rule is incorrect, but without my edit, files like /admin/pages.php didn't show up - all very odd.

Any help anyone could offer would be greatly appreciated!

(Edited to clarify when error occurred)
Reply
#17
@asd102 i just tested GS 3.2 (latest official non beta) with the basic config (the one in the first post) and setup worked like a charm.

sorry, i can't reproduce your problem.
Reply
#18
(2013-03-08, 21:31:56)marrco Wrote: @asd102 i just tested GS 3.2 (latest official non beta) with the basic config (the one in the first post) and setup worked like a charm.

sorry, i can't reproduce your problem.

Thank you for checking... I'm using the fresh GS 3.2 too.

nginx version 1.2.7

I've just tried a completely fresh virtual host with the exact conf from the first thread - only changing my server_name and root directives and got the same problem... visiting the root of my site gives this:

http://example.com/index.php/admin/install.php

Chrome error: This page has a redirect loop

This suggests to me that it is something to do with my nginx.conf, but there is no reference to any locations here either...

I followed most of this tutorial to set up php5-fpm on my VPS.
http://www.rackspace.com/knowledge_cente...-for-nginx

I really appreciate any help you can give :-)
Reply
#19
@asd102 remove this line: access_log off; and check both /var/log/nginx/errror.log and accesss.log.
Don't forget to reload php/nginx when you modify config files.

I'm using debian squeeze and installed nginx from backports. My guess is that you didn't read the first error message, maybe it was just unable to continue setup because of some directory permission error, and then you modified the config creating the loop, and never restarted nginx.
Reply
#20
(2013-03-09, 00:52:05)marrco Wrote: @asd102 remove this line: access_log off; and check both /var/log/nginx/errror.log and accesss.log.
Don't forget to reload php/nginx when you modify config files.

I'm using debian squeeze and installed nginx from backports. My guess is that you didn't read the first error message, maybe it was just unable to continue setup because of some directory permission error, and then you modified the config creating the loop, and never restarted nginx.

@marrco access_log is off, and I have indeed been stopping and starting nginx after every config file edit - but good to check.

It's something to do with how nginx is re-writing the files...

visiting the root of the site gives me:
http://example.com/index.php/admin/install.php

Removing the offending "index.php" allows me to view this page:
http://example.com/admin/install.php

And click through into:
http://example.com/admin/setup.php

Filling in the form and clicking "install now" gives me this URL:
http://example.com/index.php/admin/install.php

It turns out that I installed nginx from DotDeb, not backports... would that matter? I have just checked, my version is 1.2.7, backports is 1.2.1

---
EDIT:
It is the re-write rule as this is in the error log:
2013/03/08 15:23:35 [error] 30224#0: *45 open() "/route/to/example.com/setup.php/admin/template/js/fancybox/jquery.fancybox.pack.js" failed (2: No such file or directory), client: IP, server:example.com, request: "GET /setup.php/admin/template/js/fancybox/jquery.fancybox.pack.js?v=2.0.4 HTTP/1.1", host: "example.com", referrer: "http://example.com/admin/setup.php"
Reply
#21
Hi Marrco,

I have had a second attempt at sorting this on my system.

Having sifted through lots of debug messages in the error logs, I have a feeling it has something to do with fastcgi_params.

Would you be able to post your fastcgi_params file here so I can compare it with mine?

Thanks
Alex
Reply
#22
Hello.
I have a big problem with GS to work with ArchLinux/GNU and Nginx/PHP-FPM, running on a new VPS.
No problem installing and to get Nginx and PHP running, but the problem starts after installation of GS.
I have followed marrco´s configuration example ( thanks! ), but with no success.

Admin-page showes up as it should, and I can manage the site with no problem.
But when I logout and tries to access the frontpage, it will show up with no CSS styling, just text.

After checking the error.log, i found out that there was something missing in the path for the CSS-file (and some other files as well).

When the path should be /srv/http/ekevallen/theme/Cardinal/style.css it was instead looking for /srv/http/ekevallen/Cardinal/style.css.
With the "theme" folder missing.

But one funny thing is that it is working in IE, but the problem is in Chrome/Firefox.

And I have used all my Google ninja-skills, so if anyone could give me some advice, I would be a verry happy Swede!

//Andreas
Reply
#23
Hello All!

I get a "Warning: Server Setup non-Apache" error on every page. I am using Nginx 1.4.1.

Is there a configuration? I am following the tutorial, but haven't found configurations for not using Ngnix rather than Apache.

Kindest regards,
Reply
#24
@jrfiol in you have to manually edit gsconfig.php, it's in the root of your website.

Code:
# Disable check for Apache web server, default false
define('GSNOAPACHECHECK', true);
Reply
#25
Hi,

Thank you for your config, but as it was mentioned before, 3rd level links dont work. like http://xxx.ru/igri-online/ works fine, but http://xxx.ru/igri-online/masha-i-medved-idut-domoi/ doesn't. Any idea how that can be fixed?
Reply




Users browsing this thread: 2 Guest(s)