Skip to content

Commit 46d9204

Browse files
author
Volodymyr klymenko
committed
MAGETWO-35517: Optimize nginx.conf
1 parent 94e6406 commit 46d9204

File tree

1 file changed

+66
-87
lines changed

1 file changed

+66
-87
lines changed

nginx.conf.sample

+66-87
Original file line numberDiff line numberDiff line change
@@ -18,126 +18,105 @@
1818
# }
1919

2020

21-
root $MAGE_ROOT;
22-
21+
root $MAGE_ROOT/pub;
2322

2423
index index.php;
2524
autoindex off;
26-
# disable_symlinks on;
2725
charset off;
2826

29-
location /setup/ {
30-
rewrite / /setup/index.php;
31-
32-
location /setup/pub/ {}
27+
location /setup {
28+
root $MAGE_ROOT;
3329

34-
location /setup/index.php {
30+
location ~ ^/setup/index.php {
3531
fastcgi_pass fastcgi_backend;
36-
3732
fastcgi_index index.php;
3833
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3934
include fastcgi_params;
4035
}
4136
}
4237

4338
location / {
44-
root $MAGE_ROOT/pub;
45-
46-
location / {
47-
rewrite / /index.php ;
48-
}
49-
50-
location /static/ {
51-
52-
if ($MAGE_MODE = "production") {
53-
expires max;
54-
}
55-
56-
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
57-
add_header Cache-Control "public";
58-
expires +1y;
59-
60-
if (!-f $request_filename) {
61-
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
62-
}
63-
}
64-
65-
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
66-
add_header Cache-Control "no-store";
67-
expires off;
39+
try_files $uri $uri/ /index.php?$args;
40+
}
6841

69-
if (!-f $request_filename) {
70-
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
71-
}
42+
location /pub {
43+
alias $MAGE_ROOT/pub;
44+
}
7245

73-
}
46+
location /static/ {
47+
if ($MAGE_MODE = "production") {
48+
expires max;
49+
}
50+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
51+
add_header Cache-Control "public";
52+
expires +1y;
7453

7554
if (!-f $request_filename) {
7655
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
7756
}
7857
}
79-
80-
location /media/ {
81-
82-
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
83-
add_header Cache-Control "public";
84-
expires +1y;
85-
86-
if (!-f $request_filename) {
87-
rewrite / /get.php;
88-
}
89-
}
90-
91-
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
92-
add_header Cache-Control "no-store";
93-
expires off;
94-
95-
if (!-f $request_filename) {
96-
rewrite / /get.php;
97-
}
98-
}
58+
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
59+
add_header Cache-Control "no-store";
60+
expires off;
9961

10062
if (!-f $request_filename) {
101-
rewrite / /get.php;
63+
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
10264
}
10365
}
104-
105-
location /media/customer/ {
106-
deny all;
66+
if (!-f $request_filename) {
67+
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
10768
}
69+
}
10870

109-
location /media/downloadable/ {
110-
deny all;
71+
location /media/ {
72+
try_files $uri $uri/ /get.php?$args;
73+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
74+
add_header Cache-Control "public";
75+
expires +1y;
76+
try_files $uri $uri/ /get.php?$args;
11177
}
112-
113-
location ~ /media/theme_customization/.*\.xml$ {
114-
deny all;
78+
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
79+
add_header Cache-Control "no-store";
80+
expires off;
81+
try_files $uri $uri/ /get.php?$args;
11582
}
83+
}
11684

117-
location /errors/ {
118-
try_files $uri =404;
119-
}
85+
location /media/customer/ {
86+
deny all;
87+
}
12088

121-
location ~ ^/errors/.*\.(xml|phtml)$ {
122-
deny all;
123-
}
89+
location /media/downloadable/ {
90+
deny all;
91+
}
12492

125-
location ~ cron\.php {
126-
deny all;
127-
}
93+
location ~ /media/theme_customization/.*\.xml$ {
94+
deny all;
95+
}
12896

129-
location ~ (index|get|static|report|404|503)\.php$ {
130-
expires -1;
131-
fastcgi_pass fastcgi_backend;
97+
location /errors/ {
98+
try_files $uri =404;
99+
}
132100

133-
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
134-
fastcgi_param PHP_VALUE "memory_limit=256M \n max_execution_time=600";
135-
fastcgi_read_timeout 600s;
136-
fastcgi_connect_timeout 600s;
137-
fastcgi_param MAGE_MODE $MAGE_MODE;
101+
location ~ ^/errors/.*\.(xml|phtml)$ {
102+
deny all;
103+
}
138104

139-
fastcgi_index index.php;
140-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
141-
include fastcgi_params;
142-
}
105+
location ~ cron\.php {
106+
deny all;
107+
}
108+
109+
location ~ (index|get|static|report|404|503)\.php$ {
110+
try_files $uri =404;
111+
fastcgi_pass fastcgi_backend;
112+
113+
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
114+
fastcgi_param PHP_VALUE "memory_limit=256M \n max_execution_time=600";
115+
fastcgi_read_timeout 600s;
116+
fastcgi_connect_timeout 600s;
117+
fastcgi_param MAGE_MODE $MAGE_MODE;
118+
119+
fastcgi_index index.php;
120+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
121+
include fastcgi_params;
143122
}

0 commit comments

Comments
 (0)