PageRenderTime 38ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/http/Provision/Config/Nginx/Inc/vhost_include.tpl.php

https://gitlab.com/aegir/provision
PHP | 1522 lines | 1052 code | 110 blank | 360 comment | 191 complexity | deb459d948588e7acd5efdf87d98b63a MD5 | raw file
  1. <?php
  2. $script_user = drush_get_option('script_user');
  3. if (!$script_user && $server->script_user) {
  4. $script_user = $server->script_user;
  5. }
  6. $aegir_root = drush_get_option('aegir_root');
  7. if (!$aegir_root && $server->aegir_root) {
  8. $aegir_root = $server->aegir_root;
  9. }
  10. $nginx_config_mode = drush_get_option('nginx_config_mode');
  11. if (!$nginx_config_mode && $server->nginx_config_mode) {
  12. $nginx_config_mode = $server->nginx_config_mode;
  13. }
  14. $phpfpm_mode = drush_get_option('phpfpm_mode');
  15. if (!$phpfpm_mode && $server->phpfpm_mode) {
  16. $phpfpm_mode = $server->phpfpm_mode;
  17. }
  18. // We can use $server here once we have proper inheritance.
  19. // See Provision_Service_http_nginx_ssl for details.
  20. $phpfpm_socket_path = Provision_Service_http_nginx::getPhpFpmSocketPath();
  21. $nginx_is_modern = drush_get_option('nginx_is_modern');
  22. if (!$nginx_is_modern && $server->nginx_is_modern) {
  23. $nginx_is_modern = $server->nginx_is_modern;
  24. }
  25. $nginx_has_etag = drush_get_option('nginx_has_etag');
  26. if (!$nginx_has_etag && $server->nginx_has_etag) {
  27. $nginx_has_etag = $server->nginx_has_etag;
  28. }
  29. $nginx_has_http2 = drush_get_option('nginx_has_http2');
  30. if (!$nginx_has_http2 && $server->nginx_has_http2) {
  31. $nginx_has_http2 = $server->nginx_has_http2;
  32. }
  33. $nginx_has_gzip = drush_get_option('nginx_has_gzip');
  34. if (!$nginx_has_gzip && $server->nginx_has_gzip) {
  35. $nginx_has_gzip = $server->nginx_has_gzip;
  36. }
  37. $nginx_has_upload_progress = drush_get_option('nginx_has_upload_progress');
  38. if (!$nginx_has_upload_progress && $server->nginx_has_upload_progress) {
  39. $nginx_has_upload_progress = $server->nginx_has_upload_progress;
  40. }
  41. $satellite_mode = drush_get_option('satellite_mode');
  42. if (!$satellite_mode && $server->satellite_mode) {
  43. $satellite_mode = $server->satellite_mode;
  44. }
  45. ?>
  46. #######################################################
  47. <?php if ($nginx_config_mode == 'extended'): ?>
  48. ### nginx.conf site level extended vhost include start
  49. <?php else: ?>
  50. ### nginx.conf site level basic vhost include start
  51. <?php endif; ?>
  52. #######################################################
  53. ###
  54. ### Use the main site name if available, instead of
  55. ### potentially virtual server_name when alias is set
  56. ### as redirection target. See #2358977 for details.
  57. ###
  58. if ($main_site_name = '') {
  59. set $main_site_name "$server_name";
  60. }
  61. ###
  62. ### Mitigation for https://www.drupal.org/SA-CORE-2018-002
  63. ###
  64. set $rce "ZZ";
  65. if ( $query_string ~* (23value|23default_value|element_parents=%23) ) {
  66. set $rce "A";
  67. }
  68. if ( $request_method = POST ) {
  69. set $rce "${rce}B";
  70. }
  71. if ( $rce = "AB" ) {
  72. return 403;
  73. }
  74. <?php if ($nginx_config_mode == 'extended'): ?>
  75. set $nocache_details "Cache";
  76. <?php if ($satellite_mode == 'boa'): ?>
  77. ###
  78. ### Return 404 on special PHP URLs to avoid revealing version used,
  79. ### even indirectly. See also: https://drupal.org/node/2116387
  80. ###
  81. if ( $args ~* "=PHP[A-Z0-9]{8}-" ) {
  82. return 404;
  83. }
  84. ###
  85. ### Deny crawlers.
  86. ###
  87. if ($is_crawler) {
  88. return 403;
  89. }
  90. ###
  91. ### Block semalt botnet.
  92. ###
  93. if ($is_botnet) {
  94. return 403;
  95. }
  96. ###
  97. ### Include high load protection config if exists.
  98. ###
  99. include /data/conf/nginx_high_load.c*;
  100. <?php endif; ?>
  101. ###
  102. ### Deny not compatible request methods without 405 response.
  103. ###
  104. if ( $request_method !~ ^(?:GET|HEAD|POST|PUT|DELETE|OPTIONS)$ ) {
  105. return 403;
  106. }
  107. <?php if ($nginx_config_mode == 'extended'): ?>
  108. ###
  109. ### Deny listed requests for security reasons.
  110. ###
  111. if ($is_denied) {
  112. return 403;
  113. }
  114. ###
  115. ### Add recommended HTTP headers
  116. ###
  117. add_header X-Content-Type-Options nosniff;
  118. add_header X-XSS-Protection "1; mode=block";
  119. <?php endif; ?>
  120. <?php if ($satellite_mode == 'boa'): ?>
  121. ###
  122. ### Force clean URLs for Drupal 8.
  123. ###
  124. rewrite ^/index.php/(.*)$ $scheme://$host/$1 permanent;
  125. ###
  126. ### Include high level local configuration override if exists.
  127. ###
  128. include <?php print $aegir_root; ?>/config/server_master/nginx/post.d/nginx_force_include*;
  129. ###
  130. ### Include PHP-FPM version override logic if exists.
  131. ###
  132. include <?php print $aegir_root; ?>/config/server_master/nginx/post.d/fpm_include*;
  133. ###
  134. ### Allow to use non-default PHP-FPM version for the site
  135. ### listed in the special include file.
  136. ###
  137. if ($user_socket = '') {
  138. set $user_socket "<?php print $script_user; ?>";
  139. }
  140. <?php endif; ?>
  141. ###
  142. ### HTTPRL standard support.
  143. ###
  144. location ^~ /httprl_async_function_callback {
  145. location ~* ^/httprl_async_function_callback {
  146. access_log off;
  147. set $nocache_details "Skip";
  148. try_files $uri @drupal;
  149. }
  150. }
  151. ###
  152. ### HTTPRL test mode support.
  153. ###
  154. location ^~ /admin/httprl-test {
  155. location ~* ^/admin/httprl-test {
  156. access_log off;
  157. set $nocache_details "Skip";
  158. try_files $uri @drupal;
  159. }
  160. }
  161. ###
  162. ### CDN Far Future expiration support.
  163. ###
  164. location ^~ /cdn/farfuture/ {
  165. access_log off;
  166. log_not_found off;
  167. <?php if ($nginx_has_etag): ?>
  168. etag off;
  169. <?php else: ?>
  170. add_header ETag "";
  171. <?php endif; ?>
  172. gzip_http_version 1.1;
  173. if_modified_since exact;
  174. set $nocache_details "Skip";
  175. location ~* ^/cdn/farfuture/.+\.(?:css|js|jpe?g|gif|png|ico|bmp|svg|swf|pdf|docx?|xlsx?|pptx?|tiff?|txt|rtf|class|otf|ttf|woff2?|eot|less)$ {
  176. expires max;
  177. add_header X-Header "CDN Far Future Generator 1.0";
  178. add_header Cache-Control "no-transform, public";
  179. add_header Last-Modified "Wed, 20 Jan 1988 04:20:42 GMT";
  180. add_header Access-Control-Allow-Origin *;
  181. add_header X-Content-Type-Options nosniff;
  182. add_header X-XSS-Protection "1; mode=block";
  183. rewrite ^/cdn/farfuture/[^/]+/[^/]+/(.+)$ /$1 break;
  184. try_files $uri @drupal;
  185. }
  186. location ~* ^/cdn/farfuture/ {
  187. expires epoch;
  188. add_header X-Header "CDN Far Future Generator 1.1";
  189. add_header Cache-Control "private, must-revalidate, proxy-revalidate";
  190. add_header Access-Control-Allow-Origin *;
  191. add_header X-Content-Type-Options nosniff;
  192. add_header X-XSS-Protection "1; mode=block";
  193. rewrite ^/cdn/farfuture/[^/]+/[^/]+/(.+)$ /$1 break;
  194. try_files $uri @drupal;
  195. }
  196. try_files $uri @drupal;
  197. }
  198. <?php endif; ?>
  199. ###
  200. ### If favicon else return error 204.
  201. ###
  202. location = /favicon.ico {
  203. access_log off;
  204. log_not_found off;
  205. expires 30d;
  206. add_header Access-Control-Allow-Origin *;
  207. add_header X-Content-Type-Options nosniff;
  208. add_header X-XSS-Protection "1; mode=block";
  209. try_files /sites/$main_site_name/files/favicon.ico $uri =204;
  210. }
  211. ###
  212. ### Support for https://drupal.org/project/robotstxt module
  213. ### and static file in the sites/domain/files directory.
  214. ###
  215. location = /robots.txt {
  216. access_log off;
  217. log_not_found off;
  218. add_header Access-Control-Allow-Origin *;
  219. add_header X-Content-Type-Options nosniff;
  220. add_header X-XSS-Protection "1; mode=block";
  221. <?php if ($nginx_config_mode == 'extended'): ?>
  222. try_files /sites/$main_site_name/files/$host.robots.txt /sites/$main_site_name/files/robots.txt $uri @cache;
  223. <?php else: ?>
  224. try_files /sites/$main_site_name/files/$host.robots.txt /sites/$main_site_name/files/robots.txt $uri @drupal;
  225. <?php endif; ?>
  226. }
  227. ###
  228. ### Support for static ads.txt file in the sites/domain/files directory.
  229. ###
  230. location = /ads.txt {
  231. access_log off;
  232. log_not_found off;
  233. add_header Access-Control-Allow-Origin *;
  234. add_header X-Content-Type-Options nosniff;
  235. add_header X-XSS-Protection "1; mode=block";
  236. try_files /sites/$main_site_name/files/$host.ads.txt /sites/$main_site_name/files/ads.txt $uri =404;
  237. }
  238. <?php if ($satellite_mode == 'boa'): ?>
  239. ###
  240. ### Allow local access to the FPM status page.
  241. ###
  242. location = /fpm-status {
  243. access_log off;
  244. allow 127.0.0.1;
  245. deny all;
  246. <?php if ($satellite_mode == 'boa'): ?>
  247. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  248. <?php elseif ($phpfpm_mode == 'port'): ?>
  249. fastcgi_pass 127.0.0.1:9000;
  250. <?php else: ?>
  251. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  252. <?php endif; ?>
  253. }
  254. ###
  255. ### Allow local access to the FPM ping URI.
  256. ###
  257. location = /fpm-ping {
  258. access_log off;
  259. allow 127.0.0.1;
  260. deny all;
  261. <?php if ($satellite_mode == 'boa'): ?>
  262. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  263. <?php elseif ($phpfpm_mode == 'port'): ?>
  264. fastcgi_pass 127.0.0.1:9000;
  265. <?php else: ?>
  266. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  267. <?php endif; ?>
  268. }
  269. <?php endif; ?>
  270. <?php if ($nginx_config_mode == 'extended'): ?>
  271. ###
  272. ### Allow local access to support wget method in Aegir settings
  273. ### for running sites cron.
  274. ###
  275. location = /cron.php {
  276. <?php if ($satellite_mode == 'boa'): ?>
  277. allow 127.0.0.1;
  278. deny all;
  279. <?php endif; ?>
  280. try_files $uri =404;
  281. <?php if ($satellite_mode == 'boa'): ?>
  282. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  283. <?php elseif ($phpfpm_mode == 'port'): ?>
  284. fastcgi_pass 127.0.0.1:9000;
  285. <?php else: ?>
  286. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  287. <?php endif; ?>
  288. }
  289. ###
  290. ### Allow local access to support wget method in Aegir settings
  291. ### for running sites cron in Drupal 8.
  292. ###
  293. location ^~ /cron/ {
  294. <?php if ($satellite_mode == 'boa'): ?>
  295. allow 127.0.0.1;
  296. deny all;
  297. <?php endif; ?>
  298. <?php if ($nginx_config_mode == 'extended'): ?>
  299. set $nocache_details "Skip";
  300. <?php endif; ?>
  301. try_files $uri @drupal;
  302. }
  303. ###
  304. ### Send search to php-fpm early so searching for node.js will work.
  305. ### Deny bots on search uri.
  306. ###
  307. location ^~ /search {
  308. location ~* ^/search {
  309. if ( $is_bot ) {
  310. return 403;
  311. }
  312. try_files $uri @drupal;
  313. }
  314. }
  315. ###
  316. ### Support for https://drupal.org/project/js module.
  317. ###
  318. location ^~ /js/ {
  319. location ~* ^/js/ {
  320. if ( $is_bot ) {
  321. return 403;
  322. }
  323. rewrite ^/(.*)$ /js.php?q=$1 last;
  324. }
  325. }
  326. <?php if ($nginx_has_upload_progress): ?>
  327. ###
  328. ### Upload progress support.
  329. ### https://drupal.org/project/filefield_nginx_progress
  330. ### http://github.com/masterzen/nginx-upload-progress-module
  331. ###
  332. location ~ (?<upload_form_uri>.*)/x-progress-id:(?<upload_id>\d*) {
  333. access_log off;
  334. rewrite ^ $upload_form_uri?X-Progress-ID=$upload_id;
  335. }
  336. location ^~ /progress {
  337. access_log off;
  338. upload_progress_json_output;
  339. report_uploads uploads;
  340. }
  341. <?php endif; ?>
  342. <?php if ($satellite_mode == 'boa'): ?>
  343. ###
  344. ### Deny access to Hostmaster web/db server node.
  345. ### It is still possible to edit or break web/db server
  346. ### node at /node/2/edit, if you know what are you doing.
  347. ###
  348. location ^~ /hosting/c/server_master {
  349. if ($cache_uid = '') {
  350. return 403;
  351. }
  352. if ( $is_bot ) {
  353. return 403;
  354. }
  355. access_log off;
  356. return 301 $scheme://$host/hosting/sites;
  357. }
  358. ###
  359. ### Deny access to Hostmaster db server node.
  360. ### It is still possible to edit or break db server
  361. ### node at /node/4/edit, if you know what are you doing.
  362. ###
  363. location ^~ /hosting/c/server_localhost {
  364. if ($cache_uid = '') {
  365. return 403;
  366. }
  367. if ( $is_bot ) {
  368. return 403;
  369. }
  370. access_log off;
  371. return 301 $scheme://$host/hosting/sites;
  372. }
  373. <?php endif; ?>
  374. ###
  375. ### Fix for #2005116
  376. ###
  377. location ^~ /hosting/sites {
  378. if ( $is_bot ) {
  379. return 403;
  380. }
  381. access_log off;
  382. set $nocache_details "Skip";
  383. try_files $uri @drupal;
  384. }
  385. ###
  386. ### Fix for Aegir & .info .pl domain extensions.
  387. ###
  388. location ^~ /hosting {
  389. if ( $is_bot ) {
  390. return 403;
  391. }
  392. access_log off;
  393. set $nocache_details "Skip";
  394. try_files $uri @drupal;
  395. }
  396. <?php if ($satellite_mode == 'boa'): ?>
  397. ###
  398. ### Deny cache details display.
  399. ###
  400. location ^~ /admin/settings/performance/cache-backend {
  401. access_log off;
  402. return 301 $scheme://$host/admin/settings/performance;
  403. }
  404. ###
  405. ### Deny cache details display.
  406. ###
  407. location ^~ /admin/config/development/performance/redis {
  408. access_log off;
  409. return 301 $scheme://$host/admin/config/development/performance;
  410. }
  411. <?php endif; ?>
  412. ###
  413. ### Support for backup_migrate module download/restore/delete actions.
  414. ###
  415. location ^~ /admin {
  416. if ( $is_bot ) {
  417. return 403;
  418. }
  419. access_log off;
  420. set $nocache_details "Skip";
  421. try_files $uri @drupal;
  422. }
  423. ###
  424. ### Do not log /civicrm* requests, but protect from bots.
  425. ###
  426. location ^~ /civicrm {
  427. if ( $is_bot ) {
  428. return 403;
  429. }
  430. access_log off;
  431. ### set $nocache_details "Skip";
  432. try_files $uri @drupal;
  433. }
  434. ###
  435. ### Do not log /civicrm* requests, but protect from bots on a multi-lingual site
  436. ###
  437. location ~* ^/\w\w/civicrm {
  438. if ( $is_bot ) {
  439. return 403;
  440. }
  441. access_log off;
  442. ### set $nocache_details "Skip";
  443. try_files $uri @drupal;
  444. }
  445. ###
  446. ### Support for audio module.
  447. ###
  448. location ^~ /audio/download {
  449. location ~* ^/audio/download/.*/.*\.(?:mp3|mp4|m4a|ogg)$ {
  450. if ( $is_bot ) {
  451. return 403;
  452. }
  453. access_log off;
  454. log_not_found off;
  455. set $nocache_details "Skip";
  456. try_files $uri @drupal;
  457. }
  458. }
  459. <?php endif; ?>
  460. ###
  461. ### Deny listed requests for security reasons.
  462. ###
  463. location ~* (\.(?:git.*|htaccess|engine|config|inc|ini|info|install|make|module|profile|test|pl|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\..*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig\.save))$ {
  464. access_log off;
  465. return 404;
  466. }
  467. ###
  468. ### Deny listed requests for security reasons.
  469. ###
  470. location ~* /(?:modules|themes|libraries)/.*\.(?:txt|md)$ {
  471. access_log off;
  472. return 404;
  473. }
  474. ###
  475. ### Deny listed requests for security reasons.
  476. ###
  477. location ~* ^/sites/.*/files/civicrm/(?:ConfigAndLog|custom|upload|templates_c) {
  478. access_log off;
  479. return 404;
  480. }
  481. <?php if ($nginx_config_mode == 'extended'): ?>
  482. ###
  483. ### [Option] Deny public access to webform uploaded files
  484. ### for privacy reasons and to prevent phishing attacks.
  485. ### The files uploaded should be available only via SFTP.
  486. ###
  487. location ~* ^/sites/.*/files/webform/ {
  488. access_log off;
  489. log_not_found off;
  490. expires 99s;
  491. add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  492. add_header X-Content-Type-Options nosniff;
  493. add_header X-XSS-Protection "1; mode=block";
  494. try_files $uri =404;
  495. ### to deny the access replace the last line with:
  496. ### return 404;
  497. }
  498. location ~* ^/files/webform/ {
  499. access_log off;
  500. log_not_found off;
  501. expires 99s;
  502. add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  503. add_header X-Content-Type-Options nosniff;
  504. add_header X-XSS-Protection "1; mode=block";
  505. try_files $uri =404;
  506. ### to deny the access replace the last line with:
  507. ### return 404;
  508. }
  509. ###
  510. ### Deny often flooded URI for performance reasons
  511. ###
  512. location = /autodiscover/autodiscover.xml {
  513. access_log off;
  514. return 404;
  515. }
  516. ###
  517. ### Deny some not supported URI like cgi-bin on the Nginx level.
  518. ###
  519. location ~* (?:cgi-bin|vti-bin) {
  520. access_log off;
  521. return 404;
  522. }
  523. ###
  524. ### Deny bots on some weak modules uri.
  525. ###
  526. location ~* (?:validation|aggregator|vote_up_down|captcha|vbulletin|glossary/) {
  527. if ( $is_bot ) {
  528. return 403;
  529. }
  530. access_log off;
  531. try_files $uri @drupal;
  532. }
  533. ###
  534. ### Responsive Images support.
  535. ### https://drupal.org/project/responsive_images
  536. ###
  537. location ~* \.r\.(?:jpe?g|png|gif) {
  538. if ( $http_cookie ~* "rwdimgsize=large" ) {
  539. rewrite ^/(.*)/mobile/(.*)\.r(\.(?:jpe?g|png|gif))$ /$1/desktop/$2$3 last;
  540. }
  541. rewrite ^/(.*)\.r(\.(?:jpe?g|png|gif))$ /$1$2 last;
  542. access_log off;
  543. set $nocache_details "Skip";
  544. try_files $uri @drupal;
  545. }
  546. ###
  547. ### Adaptive Image Styles support.
  548. ### https://drupal.org/project/ais
  549. ###
  550. location ~* /(?:.+)/files/styles/adaptive/(?:.+)$ {
  551. if ( $http_cookie ~* "ais=(?<ais_cookie>[a-z0-9-_]+)" ) {
  552. rewrite ^/(.+)/files/styles/adaptive/(.+)$ /$1/files/styles/$ais_cookie/$2 last;
  553. }
  554. access_log off;
  555. set $nocache_details "Skip";
  556. try_files $uri @drupal;
  557. }
  558. <?php endif; ?>
  559. ###
  560. ### The files/styles support.
  561. ###
  562. location ~* /sites/.*/files/styles/(.*)$ {
  563. access_log off;
  564. log_not_found off;
  565. expires 30d;
  566. add_header Access-Control-Allow-Origin *;
  567. add_header X-Content-Type-Options nosniff;
  568. add_header X-XSS-Protection "1; mode=block";
  569. <?php if ($nginx_config_mode == 'extended'): ?>
  570. set $nocache_details "Skip";
  571. <?php endif; ?>
  572. try_files /sites/$main_site_name/files/styles/$1 $uri @drupal;
  573. }
  574. ###
  575. ### The s3/files/styles (s3fs) support.
  576. ###
  577. location ~* /s3/files/styles/(.*)$ {
  578. access_log off;
  579. log_not_found off;
  580. expires 30d;
  581. add_header Access-Control-Allow-Origin *;
  582. add_header X-Content-Type-Options nosniff;
  583. add_header X-XSS-Protection "1; mode=block";
  584. <?php if ($nginx_config_mode == 'extended'): ?>
  585. set $nocache_details "Skip";
  586. <?php endif; ?>
  587. try_files /sites/$main_site_name/files/styles/$1 $uri @drupal;
  588. }
  589. ###
  590. ### The files/imagecache support.
  591. ###
  592. location ~* /sites/.*/files/imagecache/(.*)$ {
  593. access_log off;
  594. log_not_found off;
  595. expires 30d;
  596. add_header Access-Control-Allow-Origin *;
  597. add_header X-Content-Type-Options nosniff;
  598. add_header X-XSS-Protection "1; mode=block";
  599. <?php if ($nginx_config_mode == 'extended'): ?>
  600. # fix common problems with old paths after import from standalone to Aegir multisite
  601. rewrite ^/sites/(.*)/files/imagecache/(.*)/sites/default/files/(.*)$ /sites/$main_site_name/files/imagecache/$2/$3 last;
  602. rewrite ^/sites/(.*)/files/imagecache/(.*)/files/(.*)$ /sites/$main_site_name/files/imagecache/$2/$3 last;
  603. set $nocache_details "Skip";
  604. <?php endif; ?>
  605. try_files /sites/$main_site_name/files/imagecache/$1 $uri @drupal;
  606. }
  607. ###
  608. ### Send requests with /external/ and /system/ URI keywords to @drupal.
  609. ###
  610. location ~* /(?:external|system)/ {
  611. access_log off;
  612. log_not_found off;
  613. expires 30d;
  614. <?php if ($nginx_config_mode == 'extended'): ?>
  615. set $nocache_details "Skip";
  616. <?php endif; ?>
  617. try_files $uri @drupal;
  618. }
  619. ###
  620. ### Deny direct access to backups.
  621. ###
  622. location ~* ^/sites/.*/files/backup_migrate/ {
  623. access_log off;
  624. deny all;
  625. }
  626. ###
  627. ### Deny direct access to config files in Drupal 8.
  628. ###
  629. location ~* ^/sites/.*/files/config_.* {
  630. access_log off;
  631. deny all;
  632. }
  633. <?php if ($satellite_mode == 'boa'): ?>
  634. ###
  635. ### Include local configuration override if exists.
  636. ###
  637. include <?php print $aegir_root; ?>/config/server_master/nginx/post.d/nginx_vhost_include*;
  638. <?php endif; ?>
  639. <?php if ($nginx_config_mode == 'extended'): ?>
  640. ###
  641. ### Private downloads are always sent to the drupal backend.
  642. ### Note: this location doesn't work with X-Accel-Redirect.
  643. ###
  644. location ~* ^/sites/.*/files/private/ {
  645. if ( $is_bot ) {
  646. return 403;
  647. }
  648. access_log off;
  649. rewrite ^/sites/.*/files/private/(.*)$ $scheme://$host/system/files/private/$1 permanent;
  650. set $nocache_details "Skip";
  651. try_files $uri @drupal;
  652. }
  653. <?php endif; ?>
  654. ###
  655. ### Deny direct access to private downloads in sites/domain/private.
  656. ### Note: this location works with X-Accel-Redirect.
  657. ###
  658. location ~* ^/sites/.*/private/ {
  659. internal;
  660. <?php if ($nginx_config_mode == 'extended'): ?>
  661. if ( $is_bot ) {
  662. return 403;
  663. }
  664. <?php endif; ?>
  665. access_log off;
  666. }
  667. <?php if ($nginx_config_mode == 'extended'): ?>
  668. ###
  669. ### Deny direct access to private downloads also for short, rewritten URLs.
  670. ### Note: this location works with X-Accel-Redirect.
  671. ###
  672. location ~* /files/private/ {
  673. internal;
  674. if ( $is_bot ) {
  675. return 403;
  676. }
  677. access_log off;
  678. }
  679. ###
  680. ### Wysiwyg Fields support.
  681. ###
  682. location ~* wysiwyg_fields/(?:plugins|scripts)/.*\.(?:js|css) {
  683. access_log off;
  684. log_not_found off;
  685. add_header Access-Control-Allow-Origin *;
  686. add_header X-Content-Type-Options nosniff;
  687. add_header X-XSS-Protection "1; mode=block";
  688. try_files $uri @drupal;
  689. }
  690. ###
  691. ### Advagg_css and Advagg_js support.
  692. ###
  693. location ~* files/advagg_(?:css|js)/ {
  694. expires max;
  695. access_log off;
  696. <?php if ($nginx_has_etag): ?>
  697. etag off;
  698. <?php else: ?>
  699. add_header ETag "";
  700. <?php endif; ?>
  701. rewrite ^/files/advagg_(.*)/(.*)$ /sites/$main_site_name/files/advagg_$1/$2 last;
  702. add_header X-Header "AdvAgg Generator 2.0";
  703. add_header Cache-Control "max-age=31449600, no-transform, public";
  704. add_header Access-Control-Allow-Origin *;
  705. add_header X-Content-Type-Options nosniff;
  706. add_header X-XSS-Protection "1; mode=block";
  707. set $nocache_details "Skip";
  708. try_files $uri @drupal;
  709. }
  710. ###
  711. ### Make css files compatible with boost caching.
  712. ###
  713. location ~* \.css$ {
  714. if ( $request_method = POST ) {
  715. return 405;
  716. }
  717. if ( $cache_uid ) {
  718. return 405;
  719. }
  720. error_page 405 = @uncached;
  721. access_log off;
  722. expires max; #if using aggregator
  723. add_header Access-Control-Allow-Origin *;
  724. add_header X-Content-Type-Options nosniff;
  725. add_header X-XSS-Protection "1; mode=block";
  726. try_files /cache/perm/$host${uri}_.css $uri =404;
  727. }
  728. ###
  729. ### Support for dynamic /sw.js requests. See #2982073 on drupal.org
  730. ###
  731. location = /sw.js {
  732. try_files $uri @drupal;
  733. }
  734. ###
  735. ### Make js files compatible with boost caching.
  736. ###
  737. location ~* \.(?:js|htc)$ {
  738. if ( $request_method = POST ) {
  739. return 405;
  740. }
  741. if ( $cache_uid ) {
  742. return 405;
  743. }
  744. error_page 405 = @uncached;
  745. access_log off;
  746. expires max; # if using aggregator
  747. add_header Access-Control-Allow-Origin *;
  748. add_header X-Content-Type-Options nosniff;
  749. add_header X-XSS-Protection "1; mode=block";
  750. try_files /cache/perm/$host${uri}_.js $uri =404;
  751. }
  752. ###
  753. ### Support for dynamic .json requests.
  754. ###
  755. location ~* \.json$ {
  756. try_files $uri @drupal;
  757. }
  758. ###
  759. ### Support for static .json files with fast 404 +Boost compatibility.
  760. ###
  761. location ~* ^/sites/.*/files/.*\.json$ {
  762. if ( $cache_uid ) {
  763. return 405;
  764. }
  765. error_page 405 = @uncached;
  766. access_log off;
  767. expires max; ### if using aggregator
  768. add_header Access-Control-Allow-Origin *;
  769. add_header X-Content-Type-Options nosniff;
  770. add_header X-XSS-Protection "1; mode=block";
  771. try_files /cache/normal/$host${uri}_.json $uri =404;
  772. }
  773. ###
  774. ### Helper location to bypass boost static files cache for logged in users.
  775. ###
  776. location @uncached {
  777. access_log off;
  778. expires max; # max if using aggregator, otherwise sane expire time
  779. }
  780. <?php endif; ?>
  781. ###
  782. ### Map /files/ shortcut early to avoid overrides in other locations.
  783. ###
  784. location ^~ /files/ {
  785. add_header Access-Control-Allow-Origin *;
  786. add_header X-Content-Type-Options nosniff;
  787. add_header X-XSS-Protection "1; mode=block";
  788. <?php if ($satellite_mode == 'boa'): ?>
  789. ###
  790. ### Sub-location to support Flash Video (FLV) files with short URIs.
  791. ###
  792. location ~* /files/.+\.flv$ {
  793. flv;
  794. expires 30d;
  795. access_log off;
  796. log_not_found off;
  797. add_header Access-Control-Allow-Origin *;
  798. add_header X-Content-Type-Options nosniff;
  799. add_header X-XSS-Protection "1; mode=block";
  800. rewrite ^/files/(.*)$ /sites/$main_site_name/files/$1 last;
  801. try_files $uri =404;
  802. }
  803. ###
  804. ### Sub-location to support H.264/AAC files with short URIs.
  805. ###
  806. location ~* /files/.+\.(?:mp4|m4a)$ {
  807. mp4;
  808. mp4_buffer_size 1m;
  809. mp4_max_buffer_size 5m;
  810. expires 30d;
  811. access_log off;
  812. log_not_found off;
  813. add_header Access-Control-Allow-Origin *;
  814. add_header X-Content-Type-Options nosniff;
  815. add_header X-XSS-Protection "1; mode=block";
  816. rewrite ^/files/(.*)$ /sites/$main_site_name/files/$1 last;
  817. try_files $uri =404;
  818. }
  819. <?php endif; ?>
  820. ###
  821. ### Sub-location to support files/styles with short URIs.
  822. ###
  823. location ~* /files/styles/(.*)$ {
  824. access_log off;
  825. log_not_found off;
  826. expires 30d;
  827. <?php if ($nginx_config_mode == 'extended'): ?>
  828. set $nocache_details "Skip";
  829. <?php endif; ?>
  830. rewrite ^/files/(.*)$ /sites/$main_site_name/files/$1 last;
  831. try_files /sites/$main_site_name/files/styles/$1 $uri @drupal;
  832. }
  833. ###
  834. ### Sub-location to support files/imagecache with short URIs.
  835. ###
  836. location ~* /files/imagecache/(.*)$ {
  837. access_log off;
  838. log_not_found off;
  839. expires 30d;
  840. <?php if ($nginx_config_mode == 'extended'): ?>
  841. # fix common problems with old paths after import from standalone to Aegir multisite
  842. rewrite ^/files/imagecache/(.*)/sites/default/files/(.*)$ /sites/$main_site_name/files/imagecache/$1/$2 last;
  843. rewrite ^/files/imagecache/(.*)/files/(.*)$ /sites/$main_site_name/files/imagecache/$1/$2 last;
  844. rewrite ^/sites/(.*)/files/imagecache/(.*)/sites/(.*)/files/(.*)$ /sites/$main_site_name/files/imagecache/$2/$4 last;
  845. set $nocache_details "Skip";
  846. <?php endif; ?>
  847. rewrite ^/files/(.*)$ /sites/$main_site_name/files/$1 last;
  848. try_files /sites/$main_site_name/files/imagecache/$1 $uri @drupal;
  849. }
  850. location ~* ^.+\.(?:pdf|jpe?g|gif|png|ico|bmp|svg|swf|docx?|xlsx?|pptx?|tiff?|txt|rtf|vcard|vcf|cgi|bat|pl|dll|class|otf|ttf|woff2?|eot|less|avi|mpe?g|mov|wmv|mp3|ogg|ogv|wav|midi|zip|tar|t?gz|rar|dmg|exe|apk|pxl|ipa|css|js)$ {
  851. expires 30d;
  852. access_log off;
  853. log_not_found off;
  854. rewrite ^/files/(.*)$ /sites/$main_site_name/files/$1 last;
  855. try_files $uri =404;
  856. }
  857. <?php if ($nginx_config_mode == 'extended'): ?>
  858. try_files $uri @cache;
  859. <?php else: ?>
  860. try_files $uri @drupal;
  861. <?php endif; ?>
  862. }
  863. ###
  864. ### Map /downloads/ shortcut early to avoid overrides in other locations.
  865. ###
  866. location ^~ /downloads/ {
  867. location ~* ^.+\.(?:pdf|jpe?g|gif|png|ico|bmp|svg|swf|docx?|xlsx?|pptx?|tiff?|txt|rtf|vcard|vcf|cgi|bat|pl|dll|class|otf|ttf|woff2?|eot|less|avi|mpe?g|mov|wmv|mp3|ogg|ogv|wav|midi|zip|tar|t?gz|rar|dmg|exe|apk|pxl|ipa)$ {
  868. expires 30d;
  869. access_log off;
  870. log_not_found off;
  871. add_header Access-Control-Allow-Origin *;
  872. add_header X-Content-Type-Options nosniff;
  873. add_header X-XSS-Protection "1; mode=block";
  874. rewrite ^/downloads/(.*)$ /sites/$main_site_name/files/downloads/$1 last;
  875. try_files $uri =404;
  876. }
  877. <?php if ($nginx_config_mode == 'extended'): ?>
  878. try_files $uri @cache;
  879. <?php else: ?>
  880. try_files $uri @drupal;
  881. <?php endif; ?>
  882. }
  883. ###
  884. ### Serve & no-log static files & images directly,
  885. ### without all standard drupal rewrites, php-fpm etc.
  886. ###
  887. location ~* ^.+\.(?:jpe?g|gif|png|ico|bmp|svg|swf|docx?|xlsx?|pptx?|tiff?|txt|rtf|vcard|vcf|cgi|bat|pl|dll|class|otf|ttf|woff2?|eot|less|mp3|wav|midi)$ {
  888. expires 30d;
  889. access_log off;
  890. log_not_found off;
  891. add_header Access-Control-Allow-Origin *;
  892. add_header X-Content-Type-Options nosniff;
  893. add_header X-XSS-Protection "1; mode=block";
  894. rewrite ^/images/(.*)$ /sites/$main_site_name/files/images/$1 last;
  895. rewrite ^/.+/sites/.+/files/(.*)$ /sites/$main_site_name/files/$1 last;
  896. try_files $uri =404;
  897. }
  898. ###
  899. ### Serve bigger media/static/archive files directly,
  900. ### without all standard drupal rewrites, php-fpm etc.
  901. ###
  902. location ~* ^.+\.(?:avi|mpe?g|mov|wmv|ogg|ogv|zip|tar|t?gz|rar|dmg|exe|apk|pxl|ipa)$ {
  903. expires 30d;
  904. access_log off;
  905. log_not_found off;
  906. add_header Access-Control-Allow-Origin *;
  907. add_header X-Content-Type-Options nosniff;
  908. add_header X-XSS-Protection "1; mode=block";
  909. rewrite ^/.+/sites/.+/files/(.*)$ /sites/$main_site_name/files/$1 last;
  910. try_files $uri =404;
  911. }
  912. ###
  913. ### Serve & no-log some static files directly,
  914. ### but only from the files directory to not break
  915. ### dynamically created pdf files or redirects for
  916. ### legacy URLs with asp/aspx extension.
  917. ###
  918. location ~* ^/sites/.+/files/.+\.(?:pdf|aspx?)$ {
  919. expires 30d;
  920. access_log off;
  921. log_not_found off;
  922. add_header Access-Control-Allow-Origin *;
  923. add_header X-Content-Type-Options nosniff;
  924. add_header X-XSS-Protection "1; mode=block";
  925. try_files $uri =404;
  926. }
  927. <?php if ($satellite_mode == 'boa'): ?>
  928. ###
  929. ### Pseudo-streaming server-side support for Flash Video (FLV) files.
  930. ###
  931. location ~* ^.+\.flv$ {
  932. flv;
  933. expires 30d;
  934. access_log off;
  935. log_not_found off;
  936. add_header Access-Control-Allow-Origin *;
  937. add_header X-Content-Type-Options nosniff;
  938. add_header X-XSS-Protection "1; mode=block";
  939. try_files $uri =404;
  940. }
  941. ###
  942. ### Pseudo-streaming server-side support for H.264/AAC files.
  943. ###
  944. location ~* ^.+\.(?:mp4|m4a)$ {
  945. mp4;
  946. mp4_buffer_size 1m;
  947. mp4_max_buffer_size 5m;
  948. expires 30d;
  949. access_log off;
  950. log_not_found off;
  951. add_header Access-Control-Allow-Origin *;
  952. add_header X-Content-Type-Options nosniff;
  953. add_header X-XSS-Protection "1; mode=block";
  954. try_files $uri =404;
  955. }
  956. <?php endif; ?>
  957. ###
  958. ### Serve & no-log some static files as is, without forcing default_type.
  959. ###
  960. location ~* /(?:cross-?domain)\.xml$ {
  961. access_log off;
  962. expires 30d;
  963. add_header Access-Control-Allow-Origin *;
  964. add_header X-Content-Type-Options nosniff;
  965. add_header X-XSS-Protection "1; mode=block";
  966. try_files $uri =404;
  967. }
  968. <?php if ($nginx_config_mode == 'extended'): ?>
  969. ###
  970. ### Allow some known php files (like serve.php in the ad module).
  971. ###
  972. location ~* /(?:modules|libraries)/(?:contrib/)?(?:ad|tinybrowser|f?ckeditor|tinymce|wysiwyg_spellcheck|ecc|civicrm|fbconnect|radioactivity|statistics)/.*\.php$ {
  973. <?php if ($satellite_mode == 'boa'): ?>
  974. limit_conn limreq 88;
  975. <?php endif; ?>
  976. access_log off;
  977. if ( $is_bot ) {
  978. return 403;
  979. }
  980. try_files $uri =404;
  981. <?php if ($satellite_mode == 'boa'): ?>
  982. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  983. <?php elseif ($phpfpm_mode == 'port'): ?>
  984. fastcgi_pass 127.0.0.1:9000;
  985. <?php else: ?>
  986. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  987. <?php endif; ?>
  988. }
  989. ###
  990. ### Deny crawlers and never cache known AJAX requests.
  991. ###
  992. location ~* /(?:ahah|ajax|batch|autocomplete|done|progress/|x-progress-id|js/.*) {
  993. if ( $is_bot ) {
  994. return 403;
  995. }
  996. access_log off;
  997. log_not_found off;
  998. <?php if ($nginx_config_mode == 'extended'): ?>
  999. set $nocache_details "Skip";
  1000. try_files $uri @drupal;
  1001. <?php else: ?>
  1002. try_files $uri @drupal;
  1003. <?php endif; ?>
  1004. }
  1005. ###
  1006. ### Serve & no-log static helper files used in some wysiwyg editors.
  1007. ###
  1008. location ~* ^/sites/.*/(?:modules|libraries)/(?:contrib/)?(?:tinybrowser|f?ckeditor|tinymce|flowplayer|jwplayer|videomanager)/.*\.(?:html?|xml)$ {
  1009. if ( $is_bot ) {
  1010. return 403;
  1011. }
  1012. access_log off;
  1013. expires 30d;
  1014. add_header Access-Control-Allow-Origin *;
  1015. add_header X-Content-Type-Options nosniff;
  1016. add_header X-XSS-Protection "1; mode=block";
  1017. try_files $uri =404;
  1018. }
  1019. ###
  1020. ### Serve & no-log any not specified above static files directly.
  1021. ###
  1022. location ~* ^/sites/.*/files/ {
  1023. access_log off;
  1024. expires 30d;
  1025. add_header Access-Control-Allow-Origin *;
  1026. add_header X-Content-Type-Options nosniff;
  1027. add_header X-XSS-Protection "1; mode=block";
  1028. try_files $uri =404;
  1029. }
  1030. ###
  1031. ### Make feeds compatible with boost caching and set correct mime type.
  1032. ###
  1033. location ~* \.xml$ {
  1034. location ~* ^/autodiscover/autodiscover\.xml {
  1035. access_log off;
  1036. return 400;
  1037. }
  1038. if ( $request_method = POST ) {
  1039. return 405;
  1040. }
  1041. if ( $cache_uid ) {
  1042. return 405;
  1043. }
  1044. error_page 405 = @drupal;
  1045. access_log off;
  1046. add_header X-Header "Boost Citrus 1.0";
  1047. add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT";
  1048. add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
  1049. add_header Access-Control-Allow-Origin *;
  1050. add_header X-Content-Type-Options nosniff;
  1051. add_header X-XSS-Protection "1; mode=block";
  1052. charset utf-8;
  1053. types { }
  1054. default_type text/xml;
  1055. try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html $uri @drupal;
  1056. }
  1057. ###
  1058. ### Deny bots on never cached uri.
  1059. ###
  1060. location ~* ^/(?:admin|user|cart|checkout|logout) {
  1061. if ( $is_bot ) {
  1062. return 403;
  1063. }
  1064. access_log off;
  1065. set $nocache_details "Skip";
  1066. try_files $uri @drupal;
  1067. }
  1068. location ~* ^/\w\w/(?:admin|user|cart|checkout|logout) {
  1069. if ( $is_bot ) {
  1070. return 403;
  1071. }
  1072. access_log off;
  1073. set $nocache_details "Skip";
  1074. try_files $uri @drupal;
  1075. }
  1076. ###
  1077. ### Protect from DoS attempts on never cached uri.
  1078. ###
  1079. location ~* ^/(?:.*/)?(?:node/[0-9]+/edit|node/add|comment/reply) {
  1080. if ( $is_bot ) {
  1081. return 403;
  1082. }
  1083. access_log off;
  1084. set $nocache_details "Skip";
  1085. try_files $uri @drupal;
  1086. }
  1087. ###
  1088. ### Protect from DoS attempts on never cached uri.
  1089. ###
  1090. location ~* ^/(?:.*/)?(?:node/[0-9]+/delete|approve) {
  1091. if ($cache_uid = '') {
  1092. return 403;
  1093. }
  1094. if ( $is_bot ) {
  1095. return 403;
  1096. }
  1097. access_log off;
  1098. set $nocache_details "Skip";
  1099. try_files $uri @drupal;
  1100. }
  1101. <?php if ($satellite_mode == 'boa'): ?>
  1102. ###
  1103. ### Support for ESI microcaching: http://groups.drupal.org/node/197478.
  1104. ###
  1105. ### This may enhance not only anonymous visitors, but also
  1106. ### logged in users experience, as it allows you to separate
  1107. ### microcache for ESI/SSI includes (valid for just 5 seconds)
  1108. ### from both default Speed Booster cache for anonymous visitors
  1109. ### (valid by default for 10s or 1h, unless purged on demand via
  1110. ### recently introduced Purge/Expire modules) and also from
  1111. ### Speed Booster cache per logged in user (valid for 10 seconds).
  1112. ###
  1113. ### Now you have three different levels of Speed Booster cache
  1114. ### to leverage and deliver the 'live content' experience for
  1115. ### all visitors, and still protect your server from DoS or
  1116. ### simply high load caused by unexpected high traffic etc.
  1117. ###
  1118. location ~ ^/(?<esi>esi/.*)"$ {
  1119. ssi on;
  1120. ssi_silent_errors on;
  1121. internal;
  1122. limit_conn limreq 888;
  1123. add_header X-Device "$device";
  1124. add_header X-Speed-Micro-Cache "$upstream_cache_status";
  1125. add_header X-Speed-Micro-Cache-Expire "5s";
  1126. add_header X-NoCache "$nocache_details";
  1127. add_header X-GeoIP-Country-Code "$geoip_country_code";
  1128. add_header X-GeoIP-Country-Name "$geoip_country_name";
  1129. add_header X-This-Proto "$http_x_forwarded_proto";
  1130. add_header X-Server-Name "$main_site_name";
  1131. add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
  1132. add_header X-Content-Type-Options nosniff;
  1133. add_header X-XSS-Protection "1; mode=block";
  1134. ###
  1135. ### Set correct, local $uri.
  1136. ###
  1137. fastcgi_param QUERY_STRING q=$esi;
  1138. fastcgi_param SCRIPT_FILENAME $document_root/index.php;
  1139. <?php if ($satellite_mode == 'boa'): ?>
  1140. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  1141. <?php elseif ($phpfpm_mode == 'port'): ?>
  1142. fastcgi_pass 127.0.0.1:9000;
  1143. <?php else: ?>
  1144. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  1145. <?php endif; ?>
  1146. ###
  1147. ### Use Nginx cache for all visitors.
  1148. ###
  1149. set $nocache "";
  1150. if ( $http_cookie ~* "NoCacheID" ) {
  1151. set $nocache "NoCache";
  1152. }
  1153. fastcgi_cache speed;
  1154. fastcgi_cache_methods GET HEAD;
  1155. fastcgi_cache_min_uses 1;
  1156. fastcgi_cache_key "$scheme$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg";
  1157. fastcgi_cache_valid 200 10s;
  1158. fastcgi_cache_valid 301 302 403 404 1s;
  1159. fastcgi_cache_valid any 1s;
  1160. fastcgi_cache_lock on;
  1161. fastcgi_ignore_headers Cache-Control Expires Vary;
  1162. fastcgi_pass_header Set-Cookie;
  1163. fastcgi_pass_header X-Accel-Expires;
  1164. fastcgi_pass_header X-Accel-Redirect;
  1165. fastcgi_no_cache $cookie_NoCacheID $http_authorization $nocache;
  1166. fastcgi_cache_bypass $cookie_NoCacheID $http_authorization $nocache;
  1167. fastcgi_cache_use_stale error http_500 http_503 invalid_header timeout updating;
  1168. expires epoch;
  1169. }
  1170. ###
  1171. ### Workaround for https://www.drupal.org/node/2599326.
  1172. ###
  1173. if ( $args ~* "/autocomplete/" ) {
  1174. return 405;
  1175. }
  1176. error_page 405 = @drupal;
  1177. <?php endif; ?>
  1178. <?php endif; ?>
  1179. ###
  1180. ### Catch all unspecified requests.
  1181. ###
  1182. location / {
  1183. <?php if ($nginx_config_mode == 'extended'): ?>
  1184. <?php if ($satellite_mode == 'boa'): ?>
  1185. if ( $http_user_agent ~* wget ) {
  1186. return 403;
  1187. }
  1188. <?php endif; ?>
  1189. try_files $uri @cache;
  1190. <?php else: ?>
  1191. try_files $uri @drupal;
  1192. <?php endif; ?>
  1193. }
  1194. <?php if ($nginx_config_mode == 'extended'): ?>
  1195. ###
  1196. ### Boost compatible cache check.
  1197. ###
  1198. location @cache {
  1199. if ( $request_method = POST ) {
  1200. set $nocache_details "Method";
  1201. return 405;
  1202. }
  1203. if ( $args ~* "nocache=1" ) {
  1204. set $nocache_details "Args";
  1205. return 405;
  1206. }
  1207. if ( $sent_http_x_force_nocache = "YES" ) {
  1208. set $nocache_details "Skip";
  1209. return 405;
  1210. }
  1211. if ( $http_cookie ~* "NoCacheID" ) {
  1212. set $nocache_details "AegirCookie";
  1213. return 405;
  1214. }
  1215. if ( $cache_uid ) {
  1216. set $nocache_details "DrupalCookie";
  1217. return 405;
  1218. }
  1219. error_page 405 = @drupal;
  1220. add_header X-Header "Boost Citrus 1.0";
  1221. add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT";
  1222. add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
  1223. add_header Access-Control-Allow-Origin *;
  1224. add_header X-Content-Type-Options nosniff;
  1225. add_header X-XSS-Protection "1; mode=block";
  1226. charset utf-8;
  1227. try_files /cache/normal/$host${uri}_$args.html @drupal;
  1228. }
  1229. <?php endif; ?>
  1230. ###
  1231. ### Send all not cached requests to drupal with clean URLs support.
  1232. ###
  1233. location @drupal {
  1234. set $core_detected "Legacy";
  1235. set $location_detected "Nowhere";
  1236. ###
  1237. ### Detect
  1238. ###
  1239. if ( -e $document_root/web.config ) {
  1240. set $core_detected "Regular";
  1241. }
  1242. if ( -e $document_root/core ) {
  1243. set $core_detected "Modern";
  1244. }
  1245. error_page 402 = @legacy;
  1246. if ( $core_detected = Legacy ) {
  1247. return 402;
  1248. }
  1249. error_page 406 = @regular;
  1250. if ( $core_detected = Regular ) {
  1251. return 406;
  1252. }
  1253. error_page 418 = @modern;
  1254. if ( $core_detected = Modern ) {
  1255. return 418;
  1256. }
  1257. ###
  1258. ### Fallback
  1259. ###
  1260. set $location_detected "Fallback";
  1261. rewrite ^ /index.php?$query_string last;
  1262. }
  1263. ###
  1264. ### Special location for Drupal 6.
  1265. ###
  1266. location @legacy {
  1267. set $location_detected "Legacy";
  1268. rewrite ^/(.*)$ /index.php?q=$1 last;
  1269. }
  1270. ###
  1271. ### Special location for Drupal 7.
  1272. ###
  1273. location @regular {
  1274. set $location_detected "Regular";
  1275. rewrite ^ /index.php?$query_string last;
  1276. }
  1277. ###
  1278. ### Special location for Drupal 8.
  1279. ###
  1280. location @modern {
  1281. set $location_detected "Modern";
  1282. try_files $uri /index.php?$query_string;
  1283. }
  1284. <?php if ($nginx_config_mode == 'extended'): ?>
  1285. ###
  1286. ### Send all non-static requests to php-fpm, restricted to known php file.
  1287. ###
  1288. location = /index.php {
  1289. <?php if ($satellite_mode == 'boa'): ?>
  1290. limit_conn limreq 88;
  1291. add_header X-Device "$device";
  1292. add_header X-GeoIP-Country-Code "$geoip_country_code";
  1293. add_header X-GeoIP-Country-Name "$geoip_country_name";
  1294. <?php endif; ?>
  1295. <?php if ($nginx_config_mode == 'extended'): ?>
  1296. add_header X-Core-Variant "$core_detected";
  1297. add_header X-Loc-Where "$location_detected";
  1298. add_header X-Http-Pragma "$http_pragma";
  1299. add_header X-Arg-Nocache "$arg_nocache";
  1300. add_header X-Arg-Comment "$arg_comment";
  1301. add_header X-Speed-Cache "$upstream_cache_status";
  1302. add_header X-Speed-Cache-UID "$cache_uid";
  1303. add_header X-Speed-Cache-Key "$key_uri";
  1304. add_header X-NoCache "$nocache_details";
  1305. add_header X-This-Proto "$http_x_forwarded_proto";
  1306. add_header X-Server-Name "$main_site_name";
  1307. add_header X-Content-Type-Options nosniff;
  1308. add_header X-XSS-Protection "1; mode=block";
  1309. <?php endif; ?>
  1310. add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
  1311. try_files $uri =404; ### check for existence of php file first
  1312. <?php if ($satellite_mode == 'boa'): ?>
  1313. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  1314. <?php elseif ($phpfpm_mode == 'port'): ?>
  1315. fastcgi_pass 127.0.0.1:9000;
  1316. <?php else: ?>
  1317. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  1318. <?php endif; ?>
  1319. <?php if ($nginx_has_upload_progress): ?>
  1320. track_uploads uploads 60s; ### required for upload progress
  1321. <?php endif; ?>
  1322. ###
  1323. ### Use Nginx cache for all visitors.
  1324. ###
  1325. set $nocache "";
  1326. if ( $nocache_details ~ (?:AegirCookie|Args|Skip) ) {
  1327. set $nocache "NoCache";
  1328. }
  1329. add_header X-Debug-NoCache-Switch "$nocache";
  1330. add_header X-Debug-NoCache-Auth "$http_authorization";
  1331. add_header X-Debug-NoCache-Cookie "$cookie_NoCacheID";
  1332. fastcgi_cache speed;
  1333. fastcgi_cache_methods GET HEAD; ### Nginx default, but added for clarity
  1334. fastcgi_cache_min_uses 1;
  1335. fastcgi_cache_key "$scheme$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg";
  1336. fastcgi_cache_valid 200 10s;
  1337. fastcgi_cache_valid 301 302 403 404 1s;
  1338. fastcgi_cache_valid any 1s;
  1339. fastcgi_cache_lock on;
  1340. fastcgi_ignore_headers Cache-Control Expires Vary;
  1341. fastcgi_pass_header Set-Cookie;
  1342. fastcgi_pass_header X-Accel-Expires;
  1343. fastcgi_pass_header X-Accel-Redirect;
  1344. fastcgi_no_cache $cookie_NoCacheID $http_authorization $nocache;
  1345. fastcgi_cache_bypass $cookie_NoCacheID $http_authorization $nocache;
  1346. fastcgi_cache_use_stale error http_500 http_503 invalid_header timeout updating;
  1347. }
  1348. <?php endif; ?>
  1349. ###
  1350. ### Send other known php requests/files to php-fpm without any caching.
  1351. ###
  1352. <?php if ($nginx_config_mode == 'extended'): ?>
  1353. location ~* ^/(?:core/)?(?:boost_stats|rtoc|js)\.php$ {
  1354. <?php else: ?>
  1355. location ~* ^/(?:index|cron|boost_stats|update|authorize|xmlrpc)\.php$ {
  1356. <?php endif; ?>
  1357. <?php if ($satellite_mode == 'boa'): ?>
  1358. limit_conn limreq 88;
  1359. if ( $is_bot ) {
  1360. return 404;
  1361. }
  1362. <?php endif; ?>
  1363. access_log off;
  1364. try_files $uri =404; ### check for existence of php file first
  1365. <?php if ($satellite_mode == 'boa'): ?>
  1366. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  1367. <?php elseif ($phpfpm_mode == 'port'): ?>
  1368. fastcgi_pass 127.0.0.1:9000;
  1369. <?php else: ?>
  1370. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  1371. <?php endif; ?>
  1372. }
  1373. <?php if ($nginx_config_mode == 'extended'): ?>
  1374. ###
  1375. ### Allow access to /authorize.php and /update.php only for logged in admin user.
  1376. ###
  1377. location ~* ^/(?:core/)?(?:authorize|update)\.php$ {
  1378. error_page 418 = @allowupdate;
  1379. if ( $cache_uid ) {
  1380. return 418;
  1381. }
  1382. return 404;
  1383. }
  1384. ###
  1385. ### Internal location for /authorize.php and /update.php restricted access.
  1386. ###
  1387. location @allowupdate {
  1388. limit_conn limreq 88;
  1389. access_log off;
  1390. try_files $uri =404; ### check for existence of php file first
  1391. <?php if ($satellite_mode == 'boa'): ?>
  1392. fastcgi_pass unix:/var/run/$user_socket.fpm.socket;
  1393. <?php elseif ($phpfpm_mode == 'port'): ?>
  1394. fastcgi_pass 127.0.0.1:9000;
  1395. <?php else: ?>
  1396. fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
  1397. <?php endif; ?>
  1398. }
  1399. <?php endif; ?>
  1400. ###
  1401. ### Deny access to any not listed above php files with 404 error.
  1402. ###
  1403. location ~* ^.+\.php$ {
  1404. return 404;
  1405. }
  1406. #######################################################
  1407. <?php if ($nginx_config_mode == 'extended'): ?>
  1408. ### nginx.conf site level extended vhost include end
  1409. <?php else: ?>
  1410. ### nginx.conf site level basic vhost include end
  1411. <?php endif; ?>
  1412. #######################################################