Skip to content

Instantly share code, notes, and snippets.

@skyred
Last active December 27, 2018 23:29
Show Gist options
  • Select an option

  • Save skyred/4248423 to your computer and use it in GitHub Desktop.

Select an option

Save skyred/4248423 to your computer and use it in GitHub Desktop.

Revisions

  1. skyred revised this gist Dec 4, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion insready.com
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@ server {
    fastcgi_cache_lock on;
    }

    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico|ttf|svg)$ {
    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico|ttf|svg|woff)$ {
    ## If the image does not exist, maybe it must be generated by drupal (imagecache)
    try_files $uri @rewrite;
    expires 7d;
  2. skyred revised this gist Oct 9, 2015. No changes.
  3. skyred revised this gist Oct 9, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion insready.com
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ server {
    rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ \.php$ {
    location ~ \.php$|^/update.php {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    include fastcgi_params;
  4. skyred revised this gist Jun 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion insready.com
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@ server {
    fastcgi_cache_lock on;
    }

    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico|ttf)$ {
    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico|ttf|svg)$ {
    ## If the image does not exist, maybe it must be generated by drupal (imagecache)
    try_files $uri @rewrite;
    expires 7d;
  5. skyred revised this gist Feb 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion insready.com
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ server {
    fastcgi_no_cache $no_cache;

    # Set cache key to include identifying components
    fastcgi_cache_key $cache_uid@$host$request_uri;
    fastcgi_cache_key $cache_uid@$host$request_uri$request_method;

    fastcgi_cache_valid 200 301 15s;
    fastcgi_cache_valid 302 1m;
  6. skyred revised this gist Jul 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion insready.com
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ server {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/tmp/php-fpm.sock;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    fastcgi_cache microcache;
    fastcgi_cache_bypass $no_cache;
  7. skyred revised this gist Aug 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion insready.com
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@ server {
    fastcgi_cache_lock on;
    }

    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico)$ {
    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico|ttf)$ {
    ## If the image does not exist, maybe it must be generated by drupal (imagecache)
    try_files $uri @rewrite;
    expires 7d;
  8. skyred revised this gist Aug 2, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions insready.com
    Original file line number Diff line number Diff line change
    @@ -82,4 +82,10 @@ server {
    expires 7d;
    log_not_found off;
    }

    ## private files protection
    location ~ ^/sites/.*/private/ {
    access_log off;
    deny all;
    }
    }
  9. skyred revised this gist Aug 2, 2013. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions insready.com
    Original file line number Diff line number Diff line change
    @@ -76,13 +76,10 @@ server {
    fastcgi_cache_lock on;
    }

    # Catch image styles for D7.
    location ~ ^/sites/.*/files/styles/ {
    location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico)$ {
    ## If the image does not exist, maybe it must be generated by drupal (imagecache)
    try_files $uri @rewrite;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    expires 7d;
    log_not_found off;
    }
    }
  10. skyred revised this gist Dec 21, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions insready.com
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,8 @@ server {
    fastcgi_pass unix:/tmp/php-fpm.sock;

    fastcgi_cache microcache;
    fastcgi_cache_bypass $no_cache;
    fastcgi_no_cache $no_cache;

    # Set cache key to include identifying components
    fastcgi_cache_key $cache_uid@$host$request_uri;
  11. skyred revised this gist Dec 19, 2012. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions insready.com
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,3 @@
    fastcgi_cache_path /dev/shm/microcache levels=1:2 keys_zone=microcache:5M max_size=1G inactive=2h;
    map $http_cookie $cache_uid {
    default nil; # hommage to Lisp :)
    ~SESS[[:alnum:]]+=(?<session_id>[[:alnum:]]+) $session_id;
    }

    server {
    server_name www.insready.com;
    root /srv/www/insready.com/public_html; ## <-- Your only path reference.
  12. skyred revised this gist Dec 11, 2012. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions insready.com
    Original file line number Diff line number Diff line change
    @@ -67,7 +67,16 @@ server {
    fastcgi_ignore_headers Cache-Control Expires;
    fastcgi_pass_header Set-Cookie;
    fastcgi_pass_header Cookie;

    ## Add a cache miss/hit status header.
    add_header X-Micro-Cache $upstream_cache_status;

    ## To avoid any interaction with the cache control headers we expire
    ## everything on this location immediately.
    expires epoch;

    ## Cache locking mechanism for protecting the backend of too many
    ## simultaneous requests.
    fastcgi_cache_lock on;
    }

  13. skyred renamed this gist Dec 10, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  14. skyred revised this gist Dec 10, 2012. 1 changed file with 5 additions and 26 deletions.
    31 changes: 5 additions & 26 deletions Drupal-Nginx
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    fastcgi_cache_path /dev/shm/microcache levels=1:2 keys_zone=microcache:5M max_size=1G inactive=2h;
    fastcgi_cache_key $scheme$host$request_method$request_uri;
    map $http_cookie $cache_uid {
    default nil; # hommage to Lisp :)
    ~SESS[[:alnum:]]+=(?<session_id>[[:alnum:]]+) $session_id;
    }

    server {
    server_name www.insready.com;
    @@ -51,34 +54,10 @@ server {
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/tmp/php-fpm.sock;

    # Setup var defaults
    set $no_cache "";

    # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
    if ($request_method !~ ^(GET|HEAD)$) {
    set $no_cache "1";
    }

    # Drop no cache cookie if need be
    # (for some reason, add_header fails if included in prior if-block)
    if ($no_cache = "1") {
    add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
    add_header X-Microcachable "0";
    }

    # Bypass cache if no-cache cookie is set
    if ($http_cookie ~* "_mcnc") {
    set $no_cache "1";
    }

    # Bypass cache if flag is set
    fastcgi_no_cache $no_cache;
    fastcgi_cache_bypass $no_cache;


    fastcgi_cache microcache;

    # Set cache key to include identifying components
    fastcgi_cache_key $cache_uid@$host$request_uri;

    fastcgi_cache_valid 200 301 15s;
    fastcgi_cache_valid 302 1m;
  15. skyred revised this gist Dec 10, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Drupal-Nginx
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,10 @@ fastcgi_cache_path /dev/shm/microcache levels=1:2 keys_zone=microcache:5M max_si
    fastcgi_cache_key $scheme$host$request_method$request_uri;

    server {
    server_name aegir.insready.com;
    root /srv/www/aegir.insready.com/public_html; ## <-- Your only path reference.
    access_log /srv/www/aegir.insready.com/logs/access.log;
    error_log /srv/www/aegir.insready.com/logs/error.log;
    server_name www.insready.com;
    root /srv/www/insready.com/public_html; ## <-- Your only path reference.
    access_log /srv/www/insready.com/logs/access.log;
    error_log /srv/www/insready.com/logs/error.log;

    location = /favicon.ico {
    log_not_found off;
  16. skyred created this gist Dec 10, 2012.
    104 changes: 104 additions & 0 deletions Drupal-Nginx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,104 @@
    fastcgi_cache_path /dev/shm/microcache levels=1:2 keys_zone=microcache:5M max_size=1G inactive=2h;
    fastcgi_cache_key $scheme$host$request_method$request_uri;

    server {
    server_name aegir.insready.com;
    root /srv/www/aegir.insready.com/public_html; ## <-- Your only path reference.
    access_log /srv/www/aegir.insready.com/logs/access.log;
    error_log /srv/www/aegir.insready.com/logs/error.log;

    location = /favicon.ico {
    log_not_found off;
    access_log off;
    }

    location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    }

    # This matters if you use drush
    location = /backup {
    deny all;
    }

    # Very rarely should these ever be accessed outside of your lan
    location ~* \.(txt|log)$ {
    deny all;
    }

    location ~ \..*/.*\.php$ {
    return 403;
    }

    location / {
    # This is cool because no php is touched for static content
    try_files $uri @rewrite;
    }

    location @rewrite {
    # Some modules enforce no slash (/) at the end of the URL
    # Else this rewrite block wouldn't be needed (GlobalRedirect)
    rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/tmp/php-fpm.sock;

    # Setup var defaults
    set $no_cache "";

    # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
    if ($request_method !~ ^(GET|HEAD)$) {
    set $no_cache "1";
    }

    # Drop no cache cookie if need be
    # (for some reason, add_header fails if included in prior if-block)
    if ($no_cache = "1") {
    add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
    add_header X-Microcachable "0";
    }

    # Bypass cache if no-cache cookie is set
    if ($http_cookie ~* "_mcnc") {
    set $no_cache "1";
    }

    # Bypass cache if flag is set
    fastcgi_no_cache $no_cache;
    fastcgi_cache_bypass $no_cache;


    fastcgi_cache microcache;

    # Set cache key to include identifying components

    fastcgi_cache_valid 200 301 15s;
    fastcgi_cache_valid 302 1m;
    fastcgi_cache_valid 404 1s;
    fastcgi_cache_min_uses 1;
    fastcgi_cache_use_stale error timeout invalid_header updating http_500;
    fastcgi_ignore_headers Cache-Control Expires;
    fastcgi_pass_header Set-Cookie;
    fastcgi_pass_header Cookie;
    expires epoch;
    fastcgi_cache_lock on;
    }

    # Catch image styles for D7.
    location ~ ^/sites/.*/files/styles/ {
    try_files $uri @rewrite;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
    }
    }