m7v
7/8/2014 - 4:21 PM

nginx Drupal

nginx Drupal

server {
  listen 8080;
  index index.php index.html index.htm;

  server_name d7.loc www.d7.loc;
  root /home/andrew/Projects/d7;

  client_body_buffer_size 4m;
  client_max_body_size 128m;
  fastcgi_buffers 64 16k;

  error_log /var/log/nginx/d7.error.log;
  access_log /var/log/nginx/d7.access.log;

  error_page 404 = @rewrite;                                                                                                                
  error_page 403 = @rewrite;                                                                   
  location ^~ /.ht* {                                                  
    deny all;                                                          
  }                                                                                          
  location ^~ /.inc* {                                                 
    deny all;                                                          
  }

  location ^~ /.git {
    return 404;
  }

  location ^~ /patches {
    return 404;
  }

  location ^~ /backup {
    return 404;
  }

  location = /robots.txt {
    access_log off;
    expires 30d;
  }

  location ~ ^/sites/.*/private {
    return 403;
  }

  location ~ ^/sites/.*/files/imagecache/ {
    try_files $uri @rewrite;
    access_log      off;
    log_not_found   off;
    expires         30d;
  }

  location ~ ^/sites/.*/files/styles/ {
    try_files $uri @rewrite;
    access_log      off;
    log_not_found   off;
    expires         30d;
  }

  location /js/ {
    rewrite ^(.*)$ /js.php?q=$1;
  }

  location /crontab {
    location ~ \.php$ {
      include                 fastcgi_params;
      fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_read_timeout    300;
      fastcgi_send_timeout    300;
      fastcgi_connect_timeout 300;
      fastcgi_pass            unix:/var/run/php5-fpm.sock;
    }
  }

  location /external {
    location ~ \.php$ {
      include                 fastcgi_params;
      fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_read_timeout    300;
      fastcgi_send_timeout    300;
      fastcgi_connect_timeout 300;
      fastcgi_pass            unix:/var/run/php5-fpm.sock;
    }
  }

  location / {
    location ~* ^(?:.+\.(?:htaccess|make|txt|engine|inc|info|install|module|profile|po|sh|.*sql|test|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ {
      return 404;
    }
    try_files $uri $uri/ @rewrite;
  }

  location ~* ^.+\.(asf|asx|wax|wmv|wmx|avi|bmp|bz2|class|css|divx|doc|docx|eot|exe|flv|gif|gzip|htc|ico|jpe?g|jpe|js|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mov|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|otf|pdf|png|pot|pps|ppt|pptx|ra|ram|rar|svg|svgz|swf|tar|tbz|t?gz|tif|tiff|ttf|wav|webm|wma|woff|wri|xla|xls|xlsx|xlt|xlw|xml|zip)$ {
    access_log      off;
    log_not_found   off;
    expires         30d;
  }

  location @rewrite {
    rewrite ^ /index.php?$args;
  }

  location ~ ^/(authorize|index|xmlrpc|cron|install|update|js|sites/all/modules/contrib/elysia_cron/cron|crontab_voucher_generate)\.php$ {
    include                 fastcgi_params;
    fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout    300;
    fastcgi_send_timeout    300;
    fastcgi_connect_timeout 300;
    fastcgi_pass            unix:/var/run/php5-fpm.sock;
  }

  location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}