Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GS and NGINX
#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


Messages In This Thread
GS and NGINX - by marrco - 2011-01-24, 03:47:03
RE: GS and NGINX - by newtonuy - 2013-02-01, 03:42:38
RE: GS and NGINX - by Carlos - 2013-02-01, 04:05:56
RE: GS and NGINX - by newtonuy - 2013-02-01, 04:14:47
RE: GS and NGINX - by Carlos - 2013-02-01, 04:20:28
RE: GS and NGINX - by newtonuy - 2013-02-01, 04:21:31
RE: GS and NGINX - by asd102 - 2013-03-08, 01:12:06
RE: GS and NGINX - by marrco - 2013-03-08, 21:31:56
RE: GS and NGINX - by asd102 - 2013-03-09, 00:31:07
RE: GS and NGINX - by marrco - 2013-03-09, 00:52:05
RE: GS and NGINX - by asd102 - 2013-03-09, 01:37:31
RE: GS and NGINX - by asd102 - 2013-05-09, 23:26:18
RE: GS and NGINX - by dillingen - 2013-05-29, 21:09:05
RE: GS and NGINX - by jrfiol - 2013-06-22, 05:10:31
RE: GS and NGINX - by marrco - 2013-06-24, 19:04:20
RE: GS and NGINX - by eremini - 2013-09-20, 01:56:34
RE: GS and NGINX - by Everyone - 2013-09-20, 03:33:55
RE: GS and NGINX - by shawn_a - 2013-09-20, 04:02:04
RE: GS and NGINX - by Everyone - 2013-09-20, 18:57:11
RE: GS and NGINX - by marrco - 2014-05-10, 00:52:34
RE: GS and NGINX - by shawn_a - 2014-05-10, 01:38:41
RE: GS and NGINX - by cviebrock - 2014-06-05, 13:53:08
RE: GS and NGINX - by scote - 2014-12-01, 16:44:38
GS and NGINX - by BillF - 2011-01-26, 04:28:39
GS and NGINX - by marrco - 2011-03-08, 04:53:54
GS and NGINX - by [/root.] - 2012-02-07, 05:22:30
RE: GS and NGINX - by plahpoy - 2018-08-25, 09:10:49
GS and NGINX - by marrco - 2012-02-29, 21:26:06
GS and NGINX - by SoftExpert - 2012-03-18, 21:29:53
GS and NGINX - by marrco - 2012-03-19, 19:18:08
GS and NGINX - by incognito - 2012-03-23, 00:36:43
GS and NGINX - by marrco - 2012-05-20, 01:28:36
GS and NGINX - by kaifas - 2012-08-13, 16:34:35



Users browsing this thread: 1 Guest(s)