From a79e2fb96864c157e5b8cbbd00c78faf45c02422 Mon Sep 17 00:00:00 2001 From: Barracuda Date: Thu, 3 Feb 2011 19:37:21 +0100 Subject: [PATCH] Re-order locations in the shared Nginx configuration files for better performance and add required in d7 authorize.php to the list of allowed php files. (Grace) --- http/nginx/nginx_advanced_include.conf | 250 ++++++++++++++++++-------------- http/nginx/nginx_simple_include.conf | 248 ++++++++++++++++++-------------- 2 files changed, 278 insertions(+), 220 deletions(-) diff --git a/http/nginx/nginx_advanced_include.conf b/http/nginx/nginx_advanced_include.conf index 50672c8..1b0b961 100644 --- a/http/nginx/nginx_advanced_include.conf +++ b/http/nginx/nginx_advanced_include.conf @@ -22,65 +22,22 @@ ### http://github.com/masterzen/nginx-upload-progress-module ### location ~ (?:.*)/x-progress-id:(?:\w*) { + access_log off; rewrite ^(.*)/x-progress-id:(\w*) $1?X-Progress-ID=$2; } location ^~ /progress { + access_log off; report_uploads uploads; } - - ### - ### deny bots on never cached uri without 403 response (and fix for Aegir & .info .pl domain ext) - ### - location ~* ^/(?:user|admin|hosting) { - if ( $http_user_agent ~* (?:crawl|goog|yahoo|spider|bot|yandex) ) { - return 444; - } - try_files $uri @cache; - } - - ### - ### deny stupid bots - ### - location ~* /node/add { - if ( $http_user_agent ~* (?:crawl|goog|yahoo|spider|bot|yandex) ) { - return 444; - } - access_log off; - try_files $uri @cache; - } ### - ### catch all unspecified requests + ### fix for Aegir & .info .pl domain ext ### - location / { + location ~* ^/(?:hosting) { + access_log off; try_files $uri @cache; } - - ### - ### boost compatible cache check - nginx 0.7.27 or newer required with try_files support - ### - location @cache { - if ( $request_method !~ ^(?:GET|HEAD)$ ) { - return 405; - } - if ( $http_cookie ~ "DRUPAL_UID" ) { - return 405; - } - error_page 405 = @drupal; - add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; - add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; - add_header X-Header "Boost Citrus 1.9"; - charset utf-8; - try_files /cache/normal/$host${uri}_$args.html @drupal; - } - - ### - ### send all not cached requests to drupal with clean URLs support - ### - location @drupal { - rewrite ^/(.*)$ /index.php?q=$1 last; - } - + ### ### deny listed requests for security reasons without 403 response ### @@ -89,54 +46,9 @@ } ### - ### deny listed requests for security reasons without 403 response - ### - location ~* (?:delete.+from|insert.+into|select.+from|union.+select|onload|script|\.php.+src|system\(.+|iframe|document\.cookie|alert|\;|\.\.) { - return 444; - } - - ### - ### allow some known php files (like serve.php in the ad module) - ### - location ~* /(?:modules|libraries)/(?:ad|tinybrowser|f?ckeditor|tinymce|wysiwyg_spellcheck)/.*\.php$ { - try_files $uri =404; - fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 - } - - ### - ### deny direct access to backups - ### - location ~* ^/sites/.*/files/backup_migrate/ { - deny all; - } - - ### - ### deny direct access to private downloads - ### - location ~* ^/sites/.*/private/ { - deny all; - } - - ### - ### send all non-static requests to php-fpm, restricted to known php files - ### - location ~* ^/(?:index|boost_stats|update|xmlrpc)\.php$ { - try_files $uri @drupal; ### check for existence of php file first - fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 - track_uploads uploads 60s; ### required for upload progress - } - - ### - ### deny access to any not listed above php files - ### - location ~* ^.+\.php$ { - deny all; - } - - ### ### make css files compatible with boost caching - nginx 0.7.27 or newer required with try_files support ### - location ~ \.css$ { + location ~* \.css$ { if ( $request_method !~ ^(?:GET|HEAD)$ ) { return 405; } @@ -153,7 +65,7 @@ ### ### make js files compatible with boost caching - nginx 0.7.27 or newer required with try_files support ### - location ~ \.js$ { + location ~* \.js$ { if ( $request_method !~ ^(?:GET|HEAD)$ ) { return 405; } @@ -170,7 +82,7 @@ ### ### make json compatible with boost caching - nginx 0.7.27 or newer required with try_files support ### - location ~ \.json$ { + location ~* \.json$ { if ( $request_method !~ ^(?:GET|HEAD)$ ) { return 405; } @@ -193,19 +105,6 @@ } ### - ### imagecache, imagecache_external and (f)ckeditor support - ### - location ~* /(?:external|system|files/imagecache|files/styles|f?ckeditor)/ { - access_log off; - expires 30d; - # fix common problems with old paths after import from standalone to Aegir multisite - rewrite ^/sites/(.*)/files/imagecache/(.*)/sites/default/files/(.*)$ /sites/$host/files/imagecache/$2/$3 last; - rewrite ^/files/imagecache/(.*)$ /sites/$host/files/imagecache/$1 last; - rewrite ^/files/styles/(.*)$ /sites/$host/files/styles/$1 last; - try_files $uri @drupal; - } - - ### ### serve & no-log static files & images directly, without all standard drupal rewrites, php-fpm etc. ### location ~* ^.+\.(?:jpe?g|gif|png|ico|swf|pdf|doc|xls|tiff?|txt|cgi|bat|pl|dll|aspx?|exe|class)$ { @@ -235,10 +134,18 @@ location ~* /(?:cross-?domain)\.xml$ { access_log off; expires 30d; + add_header X-Header "Barracuda Octopus 1.0"; try_files $uri =404; } ### + ### deny listed requests for security reasons without 403 response + ### + location ~* (?:delete.+from|insert.+into|select.+from|union.+select|onload|script|\.php.+src|system\(.+|iframe|document\.cookie|alert|\;|\.\.) { + return 444; + } + + ### ### make feeds compatible with boost caching and set correct mime type - nginx 0.7.27 or newer required with try_files support ### location ~* \.xml$ { @@ -249,6 +156,7 @@ return 405; } error_page 405 = @drupal; + access_log off; add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; add_header X-Header "Boost Citrus 2.4"; @@ -269,6 +177,7 @@ return 405; } error_page 405 = @drupal; + access_log off; add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; add_header X-Header "Boost Citrus 2.5"; @@ -278,6 +187,127 @@ try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html $uri @drupal; } + ### + ### imagecache, imagecache_external and (f)ckeditor support + ### + location ~* /(?:external|system|files/imagecache|files/styles|f?ckeditor)/ { + access_log off; + expires 30d; + # fix common problems with old paths after import from standalone to Aegir multisite + rewrite ^/sites/(.*)/files/imagecache/(.*)/sites/default/files/(.*)$ /sites/$host/files/imagecache/$2/$3 last; + rewrite ^/files/imagecache/(.*)$ /sites/$host/files/imagecache/$1 last; + rewrite ^/files/styles/(.*)$ /sites/$host/files/styles/$1 last; + try_files $uri @drupal; + } + + ### + ### deny php env display + ### + location ~* /admin/reports/status/.+ { + access_log off; + rewrite ^ http://$host/admin/reports/status permanent; + } + + ### + ### deny cache details display + ### + location ~* /admin/reports/cache { + access_log off; + rewrite ^ http://$host/admin/reports/status permanent; + } + + ### + ### deny phpinfo details display + ### + location ~* /devel/(?:phpinfo|php) { + access_log off; + rewrite ^ http://$host/admin/reports/status permanent; + } + + ### + ### deny bots on never cached uri without 403 response + ### + location ~* ^/(?:user|admin|node/add) { + if ( $http_user_agent ~* (?:crawl|goog|yahoo|spider|bot|yandex) ) { + return 444; + } + access_log off; + try_files $uri @cache; + } + + ### + ### allow some known php files (like serve.php in the ad module) + ### + location ~* /(?:modules|libraries)/(?:ad|tinybrowser|f?ckeditor|tinymce|wysiwyg_spellcheck)/.*\.php$ { + access_log off; + try_files $uri =404; + fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 + } + + ### + ### deny direct access to backups + ### + location ~* ^/sites/.*/files/backup_migrate/ { + access_log off; + deny all; + } + + ### + ### deny direct access to private downloads + ### + location ~* ^/sites/.*/private/ { + access_log off; + deny all; + } + + ### + ### catch all unspecified requests + ### + location / { + try_files $uri @cache; + } + + ### + ### boost compatible cache check - nginx 0.7.27 or newer required with try_files support + ### + location @cache { + if ( $request_method !~ ^(?:GET|HEAD)$ ) { + return 405; + } + if ( $http_cookie ~ "DRUPAL_UID" ) { + return 405; + } + error_page 405 = @drupal; + add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; + add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; + add_header X-Header "Boost Citrus 1.9"; + charset utf-8; + try_files /cache/normal/$host${uri}_$args.html @drupal; + } + + ### + ### send all not cached requests to drupal with clean URLs support + ### + location @drupal { + rewrite ^/(.*)$ /index.php?q=$1 last; + } + + ### + ### send all non-static requests to php-fpm, restricted to known php files + ### + location ~* ^/(?:index|boost_stats|update|authorize|xmlrpc)\.php$ { + try_files $uri @drupal; ### check for existence of php file first + fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 + track_uploads uploads 60s; ### required for upload progress + } + + ### + ### deny access to any not listed above php files + ### + location ~* ^.+\.php$ { + deny all; + } + ####################################################### ### nginx.conf site standard vhost include end ####################################################### diff --git a/http/nginx/nginx_simple_include.conf b/http/nginx/nginx_simple_include.conf index 8d39ace..66d4841 100644 --- a/http/nginx/nginx_simple_include.conf +++ b/http/nginx/nginx_simple_include.conf @@ -15,60 +15,15 @@ if ( $request_method !~ ^(?:GET|HEAD|POST)$ ) { return 444; } - - ### - ### deny bots on never cached uri without 403 response (and fix for Aegir & .info .pl domain ext) - ### - location ~* ^/(?:user|admin|hosting) { - if ( $http_user_agent ~* (?:crawl|goog|yahoo|spider|bot|yandex) ) { - return 444; - } - try_files $uri @cache; - } - - ### - ### deny stupid bots - ### - location ~* /node/add { - if ( $http_user_agent ~* (?:crawl|goog|yahoo|spider|bot|yandex) ) { - return 444; - } - access_log off; - try_files $uri @cache; - } - + ### - ### catch all unspecified requests + ### fix for Aegir & .info .pl domain ext ### - location / { + location ~* ^/(?:hosting) { + access_log off; try_files $uri @cache; } - - ### - ### boost compatible cache check - nginx 0.7.27 or newer required with try_files support - ### - location @cache { - if ( $request_method !~ ^(?:GET|HEAD)$ ) { - return 405; - } - if ( $http_cookie ~ "DRUPAL_UID" ) { - return 405; - } - error_page 405 = @drupal; - add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; - add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; - add_header X-Header "Boost Citrus 1.9"; - charset utf-8; - try_files /cache/normal/$host${uri}_$args.html @drupal; - } - - ### - ### send all not cached requests to drupal with clean URLs support - ### - location @drupal { - rewrite ^/(.*)$ /index.php?q=$1 last; - } - + ### ### deny listed requests for security reasons without 403 response ### @@ -77,53 +32,9 @@ } ### - ### deny listed requests for security reasons without 403 response - ### - location ~* (?:delete.+from|insert.+into|select.+from|union.+select|onload|script|\.php.+src|system\(.+|iframe|document\.cookie|alert|\;|\.\.) { - return 444; - } - - ### - ### allow some known php files (like serve.php in the ad module) - ### - location ~* /(?:modules|libraries)/(?:ad|tinybrowser|f?ckeditor|tinymce|wysiwyg_spellcheck)/.*\.php$ { - try_files $uri =404; - fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 - } - - ### - ### deny direct access to backups - ### - location ~* ^/sites/.*/files/backup_migrate/ { - deny all; - } - - ### - ### deny direct access to private downloads - ### - location ~* ^/sites/.*/private/ { - deny all; - } - - ### - ### send all non-static requests to php-fpm, restricted to known php files - ### - location ~* ^/(?:index|boost_stats|update|xmlrpc)\.php$ { - try_files $uri @drupal; ### check for existence of php file first - fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 - } - - ### - ### deny access to any not listed above php files - ### - location ~* ^.+\.php$ { - deny all; - } - - ### ### make css files compatible with boost caching - nginx 0.7.27 or newer required with try_files support ### - location ~ \.css$ { + location ~* \.css$ { if ( $request_method !~ ^(?:GET|HEAD)$ ) { return 405; } @@ -140,7 +51,7 @@ ### ### make js files compatible with boost caching - nginx 0.7.27 or newer required with try_files support ### - location ~ \.js$ { + location ~* \.js$ { if ( $request_method !~ ^(?:GET|HEAD)$ ) { return 405; } @@ -157,7 +68,7 @@ ### ### make json compatible with boost caching - nginx 0.7.27 or newer required with try_files support ### - location ~ \.json$ { + location ~* \.json$ { if ( $request_method !~ ^(?:GET|HEAD)$ ) { return 405; } @@ -180,19 +91,6 @@ } ### - ### imagecache, imagecache_external and (f)ckeditor support - ### - location ~* /(?:external|system|files/imagecache|files/styles|f?ckeditor)/ { - access_log off; - expires 30d; - # fix common problems with old paths after import from standalone to Aegir multisite - rewrite ^/sites/(.*)/files/imagecache/(.*)/sites/default/files/(.*)$ /sites/$host/files/imagecache/$2/$3 last; - rewrite ^/files/imagecache/(.*)$ /sites/$host/files/imagecache/$1 last; - rewrite ^/files/styles/(.*)$ /sites/$host/files/styles/$1 last; - try_files $uri @drupal; - } - - ### ### serve & no-log static files & images directly, without all standard drupal rewrites, php-fpm etc. ### location ~* ^.+\.(?:jpe?g|gif|png|ico|swf|pdf|doc|xls|tiff?|txt|cgi|bat|pl|dll|aspx?|exe|class)$ { @@ -222,10 +120,18 @@ location ~* /(?:cross-?domain)\.xml$ { access_log off; expires 30d; + add_header X-Header "Barracuda Octopus 1.0"; try_files $uri =404; } ### + ### deny listed requests for security reasons without 403 response + ### + location ~* (?:delete.+from|insert.+into|select.+from|union.+select|onload|script|\.php.+src|system\(.+|iframe|document\.cookie|alert|\;|\.\.) { + return 444; + } + + ### ### make feeds compatible with boost caching and set correct mime type - nginx 0.7.27 or newer required with try_files support ### location ~* \.xml$ { @@ -236,6 +142,7 @@ return 405; } error_page 405 = @drupal; + access_log off; add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; add_header X-Header "Boost Citrus 2.4"; @@ -256,6 +163,7 @@ return 405; } error_page 405 = @drupal; + access_log off; add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; add_header X-Header "Boost Citrus 2.5"; @@ -265,6 +173,126 @@ try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html $uri @drupal; } + ### + ### imagecache, imagecache_external and (f)ckeditor support + ### + location ~* /(?:external|system|files/imagecache|files/styles|f?ckeditor)/ { + access_log off; + expires 30d; + # fix common problems with old paths after import from standalone to Aegir multisite + rewrite ^/sites/(.*)/files/imagecache/(.*)/sites/default/files/(.*)$ /sites/$host/files/imagecache/$2/$3 last; + rewrite ^/files/imagecache/(.*)$ /sites/$host/files/imagecache/$1 last; + rewrite ^/files/styles/(.*)$ /sites/$host/files/styles/$1 last; + try_files $uri @drupal; + } + + ### + ### deny php env display + ### + location ~* /admin/reports/status/.+ { + access_log off; + rewrite ^ http://$host/admin/reports/status permanent; + } + + ### + ### deny cache details display + ### + location ~* /admin/reports/cache { + access_log off; + rewrite ^ http://$host/admin/reports/status permanent; + } + + ### + ### deny phpinfo details display + ### + location ~* /devel/(?:phpinfo|php) { + access_log off; + rewrite ^ http://$host/admin/reports/status permanent; + } + + ### + ### deny bots on never cached uri without 403 response + ### + location ~* ^/(?:user|admin|node/add) { + if ( $http_user_agent ~* (?:crawl|goog|yahoo|spider|bot|yandex) ) { + return 444; + } + access_log off; + try_files $uri @cache; + } + + ### + ### allow some known php files (like serve.php in the ad module) + ### + location ~* /(?:modules|libraries)/(?:ad|tinybrowser|f?ckeditor|tinymce|wysiwyg_spellcheck)/.*\.php$ { + access_log off; + try_files $uri =404; + fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 + } + + ### + ### deny direct access to backups + ### + location ~* ^/sites/.*/files/backup_migrate/ { + access_log off; + deny all; + } + + ### + ### deny direct access to private downloads + ### + location ~* ^/sites/.*/private/ { + access_log off; + deny all; + } + + ### + ### catch all unspecified requests + ### + location / { + try_files $uri @cache; + } + + ### + ### boost compatible cache check - nginx 0.7.27 or newer required with try_files support + ### + location @cache { + if ( $request_method !~ ^(?:GET|HEAD)$ ) { + return 405; + } + if ( $http_cookie ~ "DRUPAL_UID" ) { + return 405; + } + error_page 405 = @drupal; + add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT"; + add_header Cache-Control "must-revalidate, post-check=0, pre-check=0"; + add_header X-Header "Boost Citrus 1.9"; + charset utf-8; + try_files /cache/normal/$host${uri}_$args.html @drupal; + } + + ### + ### send all not cached requests to drupal with clean URLs support + ### + location @drupal { + rewrite ^/(.*)$ /index.php?q=$1 last; + } + + ### + ### send all non-static requests to php-fpm, restricted to known php files + ### + location ~* ^/(?:index|boost_stats|update|authorize|xmlrpc)\.php$ { + try_files $uri @drupal; ### check for existence of php file first + fastcgi_pass 127.0.0.1:9000; ### php-fpm listening on port 9000 + } + + ### + ### deny access to any not listed above php files + ### + location ~* ^.+\.php$ { + deny all; + } + ####################################################### ### nginx.conf site standard vhost include end ####################################################### -- 1.6.1