You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

248 line
6.8 KiB

  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.4-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 0;
  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. # Modules can be loaded only at the very beginning of the Nginx config file, please move the line below to the main config file
  29. # load_module /etc/nginx/modules/ngx_http_image_filter_module.so;
  30. root $MAGE_ROOT/pub;
  31. index index.php;
  32. autoindex off;
  33. charset UTF-8;
  34. error_page 404 403 = /errors/404.php;
  35. #add_header "X-UA-Compatible" "IE=Edge";
  36. # Deny access to sensitive files
  37. location /.user.ini {
  38. deny all;
  39. }
  40. # PHP entry point for setup application
  41. location ~* ^/setup($|/) {
  42. root $MAGE_ROOT;
  43. location ~ ^/setup/index.php {
  44. fastcgi_pass fastcgi_backend;
  45. fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
  46. fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=600";
  47. fastcgi_read_timeout 600s;
  48. fastcgi_connect_timeout 600s;
  49. fastcgi_index index.php;
  50. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  51. include fastcgi_params;
  52. }
  53. location ~ ^/setup/(?!pub/). {
  54. deny all;
  55. }
  56. location ~ ^/setup/pub/ {
  57. add_header X-Frame-Options "SAMEORIGIN";
  58. }
  59. }
  60. # PHP entry point for update application
  61. location ~* ^/update($|/) {
  62. root $MAGE_ROOT;
  63. location ~ ^/update/index.php {
  64. fastcgi_split_path_info ^(/update/index.php)(/.+)$;
  65. fastcgi_pass fastcgi_backend;
  66. fastcgi_index index.php;
  67. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  68. fastcgi_param PATH_INFO $fastcgi_path_info;
  69. include fastcgi_params;
  70. }
  71. # Deny everything but index.php
  72. location ~ ^/update/(?!pub/). {
  73. deny all;
  74. }
  75. location ~ ^/update/pub/ {
  76. add_header X-Frame-Options "SAMEORIGIN";
  77. }
  78. }
  79. location / {
  80. try_files $uri $uri/ /index.php$is_args$args;
  81. }
  82. location /pub/ {
  83. location ~ ^/pub/media/(downloadable|customer|import|custom_options|theme_customization/.*\.xml) {
  84. deny all;
  85. }
  86. alias $MAGE_ROOT/pub/;
  87. add_header X-Frame-Options "SAMEORIGIN";
  88. }
  89. location /static/ {
  90. # Uncomment the following line in production mode
  91. # expires max;
  92. # Remove signature of the static files that is used to overcome the browser cache
  93. location ~ ^/static/version\d*/ {
  94. rewrite ^/static/version\d*/(.*)$ /static/$1 last;
  95. }
  96. location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2|html|json|webmanifest)$ {
  97. add_header Cache-Control "public";
  98. add_header X-Frame-Options "SAMEORIGIN";
  99. expires +1y;
  100. if (!-f $request_filename) {
  101. rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
  102. }
  103. }
  104. location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
  105. add_header Cache-Control "no-store";
  106. add_header X-Frame-Options "SAMEORIGIN";
  107. expires off;
  108. if (!-f $request_filename) {
  109. rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
  110. }
  111. }
  112. if (!-f $request_filename) {
  113. rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
  114. }
  115. add_header X-Frame-Options "SAMEORIGIN";
  116. }
  117. location /media/ {
  118. ## The following section allows to offload image resizing from Magento instance to the Nginx.
  119. ## Catalog image URL format should be set accordingly.
  120. ## See https://docs.magento.com/user-guide/configuration/general/web.html#url-options
  121. # location ~* ^/media/catalog/.* {
  122. #
  123. # # Replace placeholders and uncomment the line below to serve product images from public S3
  124. # # See examples of S3 authentication at https://github.com/anomalizer/ngx_aws_auth
  125. # # resolver 8.8.8.8;
  126. # # proxy_pass https://<bucket-name>.<region-name>.amazonaws.com;
  127. #
  128. # set $width "-";
  129. # set $height "-";
  130. # if ($arg_width != '') {
  131. # set $width $arg_width;
  132. # }
  133. # if ($arg_height != '') {
  134. # set $height $arg_height;
  135. # }
  136. # image_filter resize $width $height;
  137. # image_filter_jpeg_quality 90;
  138. # }
  139. try_files $uri $uri/ /get.php$is_args$args;
  140. location ~ ^/media/theme_customization/.*\.xml {
  141. deny all;
  142. }
  143. location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2)$ {
  144. add_header Cache-Control "public";
  145. add_header X-Frame-Options "SAMEORIGIN";
  146. expires +1y;
  147. try_files $uri $uri/ /get.php$is_args$args;
  148. }
  149. location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
  150. add_header Cache-Control "no-store";
  151. add_header X-Frame-Options "SAMEORIGIN";
  152. expires off;
  153. try_files $uri $uri/ /get.php$is_args$args;
  154. }
  155. add_header X-Frame-Options "SAMEORIGIN";
  156. }
  157. location /media/customer/ {
  158. deny all;
  159. }
  160. location /media/downloadable/ {
  161. deny all;
  162. }
  163. location /media/import/ {
  164. deny all;
  165. }
  166. location /media/custom_options/ {
  167. deny all;
  168. }
  169. location /errors/ {
  170. location ~* \.xml$ {
  171. deny all;
  172. }
  173. }
  174. # PHP entry point for main application
  175. location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
  176. try_files $uri =404;
  177. fastcgi_pass fastcgi_backend;
  178. fastcgi_buffers 16 16k;
  179. fastcgi_buffer_size 32k;
  180. fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
  181. fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
  182. fastcgi_read_timeout 600s;
  183. fastcgi_connect_timeout 600s;
  184. fastcgi_index index.php;
  185. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  186. include fastcgi_params;
  187. }
  188. gzip on;
  189. gzip_disable "msie6";
  190. gzip_comp_level 6;
  191. gzip_min_length 1100;
  192. gzip_buffers 16 8k;
  193. gzip_proxied any;
  194. gzip_types
  195. text/plain
  196. text/css
  197. text/js
  198. text/xml
  199. text/javascript
  200. application/javascript
  201. application/x-javascript
  202. application/json
  203. application/xml
  204. application/xml+rss
  205. image/svg+xml;
  206. gzip_vary on;
  207. # Banned locations (only reached if the earlier PHP entry point regexes don't match)
  208. location ~* (\.php$|\.phtml$|\.htaccess$|\.htpasswd$|\.git) {
  209. deny all;
  210. }