nginx.conf.sample 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ## Example configuration:
  2. # upstream fastcgi_backend {
  3. # # use tcp connection
  4. # # server 127.0.0.1:9000;
  5. # # or socket
  6. # server unix:/var/run/php/php7.0-fpm.sock;
  7. # }
  8. # server {
  9. # listen 80;
  10. # server_name mage.dev;
  11. # set $MAGE_ROOT /var/www/magento2;
  12. # set $MAGE_DEBUG_SHOW_ARGS 1;
  13. # include /vagrant/magento2/nginx.conf.sample;
  14. # }
  15. #
  16. ## Optional override of deployment mode. We recommend you use the
  17. ## command 'bin/magento deploy:mode:set' to switch modes instead.
  18. ##
  19. ## set $MAGE_MODE default; # or production or developer
  20. ##
  21. ## If you set MAGE_MODE in server config, you must pass the variable into the
  22. ## PHP entry point blocks, which are indicated below. You can pass
  23. ## it in using:
  24. ##
  25. ## fastcgi_param MAGE_MODE $MAGE_MODE;
  26. ##
  27. ## In production mode, you should uncomment the 'expires' directive in the /static/ location block
  28. root $MAGE_ROOT/pub;
  29. index index.php;
  30. autoindex off;
  31. charset UTF-8;
  32. error_page 404 403 = /errors/404.php;
  33. #add_header "X-UA-Compatible" "IE=Edge";
  34. # Deny access to sensitive files
  35. location /.user.ini {
  36. deny all;
  37. }
  38. # PHP entry point for setup application
  39. location ~* ^/setup($|/) {
  40. root $MAGE_ROOT;
  41. location ~ ^/setup/index.php {
  42. fastcgi_pass fastcgi_backend;
  43. fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
  44. fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=600";
  45. fastcgi_read_timeout 600s;
  46. fastcgi_connect_timeout 600s;
  47. fastcgi_index index.php;
  48. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  49. include fastcgi_params;
  50. }
  51. location ~ ^/setup/(?!pub/). {
  52. deny all;
  53. }
  54. location ~ ^/setup/pub/ {
  55. add_header X-Frame-Options "SAMEORIGIN";
  56. }
  57. }
  58. # PHP entry point for update application
  59. location ~* ^/update($|/) {
  60. root $MAGE_ROOT;
  61. location ~ ^/update/index.php {
  62. fastcgi_split_path_info ^(/update/index.php)(/.+)$;
  63. fastcgi_pass fastcgi_backend;
  64. fastcgi_index index.php;
  65. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  66. fastcgi_param PATH_INFO $fastcgi_path_info;
  67. include fastcgi_params;
  68. }
  69. # Deny everything but index.php
  70. location ~ ^/update/(?!pub/). {
  71. deny all;
  72. }
  73. location ~ ^/update/pub/ {
  74. add_header X-Frame-Options "SAMEORIGIN";
  75. }
  76. }
  77. location / {
  78. try_files $uri $uri/ /index.php$is_args$args;
  79. }
  80. location /pub/ {
  81. location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
  82. deny all;
  83. }
  84. alias $MAGE_ROOT/pub/;
  85. add_header X-Frame-Options "SAMEORIGIN";
  86. }
  87. location /static/ {
  88. # Uncomment the following line in production mode
  89. # expires max;
  90. # Remove signature of the static files that is used to overcome the browser cache
  91. location ~ ^/static/version {
  92. rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last;
  93. }
  94. location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ {
  95. add_header Cache-Control "public";
  96. add_header X-Frame-Options "SAMEORIGIN";
  97. expires +1y;
  98. if (!-f $request_filename) {
  99. rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
  100. }
  101. }
  102. location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
  103. add_header Cache-Control "no-store";
  104. add_header X-Frame-Options "SAMEORIGIN";
  105. expires off;
  106. if (!-f $request_filename) {
  107. rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
  108. }
  109. }
  110. if (!-f $request_filename) {
  111. rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
  112. }
  113. add_header X-Frame-Options "SAMEORIGIN";
  114. }
  115. location /media/ {
  116. try_files $uri $uri/ /get.php$is_args$args;
  117. location ~ ^/media/theme_customization/.*\.xml {
  118. deny all;
  119. }
  120. location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
  121. add_header Cache-Control "public";
  122. add_header X-Frame-Options "SAMEORIGIN";
  123. expires +1y;
  124. try_files $uri $uri/ /get.php$is_args$args;
  125. }
  126. location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
  127. add_header Cache-Control "no-store";
  128. add_header X-Frame-Options "SAMEORIGIN";
  129. expires off;
  130. try_files $uri $uri/ /get.php$is_args$args;
  131. }
  132. add_header X-Frame-Options "SAMEORIGIN";
  133. }
  134. location /media/customer/ {
  135. deny all;
  136. }
  137. location /media/downloadable/ {
  138. deny all;
  139. }
  140. location /media/import/ {
  141. deny all;
  142. }
  143. # PHP entry point for main application
  144. location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
  145. try_files $uri =404;
  146. fastcgi_pass fastcgi_backend;
  147. fastcgi_buffers 1024 4k;
  148. fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
  149. fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
  150. fastcgi_read_timeout 600s;
  151. fastcgi_connect_timeout 600s;
  152. fastcgi_index index.php;
  153. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  154. include fastcgi_params;
  155. }
  156. gzip on;
  157. gzip_disable "msie6";
  158. gzip_comp_level 6;
  159. gzip_min_length 1100;
  160. gzip_buffers 16 8k;
  161. gzip_proxied any;
  162. gzip_types
  163. text/plain
  164. text/css
  165. text/js
  166. text/xml
  167. text/javascript
  168. application/javascript
  169. application/x-javascript
  170. application/json
  171. application/xml
  172. application/xml+rss
  173. image/svg+xml;
  174. gzip_vary on;
  175. # Banned locations (only reached if the earlier PHP entry point regexes don't match)
  176. location ~* (\.php$|\.htaccess$|\.git) {
  177. deny all;
  178. }