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