结果发现,在nginx中,大部分重复都是不必要的。
使用fastcgi的指令
.php
藏起来
/.ht
文件已经是regex了,所以它们会影响到所有内容。足以说明
index
有一次,如果我只想用的话,默认的东西是多余的
index.php
.
由于所有应用程序都以与web相同的方式嵌套在文件系统中,因此也不需要指定根。
令我惊讶的是
location ^~ /(system|data)/ { ... }
不仅匹配
www.example.com/system/
,而且
www.example.com/sub1/system/
. 我以为
^~
只有当开始位置与正则表达式匹配时才应该匹配…
# [non-www and http redirects]
server {
# [listen directives]
server_name www.example.com;
root /srv/app;
index index.php;
location ^~ /(system|data)/ {
return 403;
}
# Use PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
# Pass non-file URI to index.php for all locations
location /sub1/ {
try_files $uri $uri/ /sub1/index.php?$query_string;
}
location /sub2/ {
try_files $uri $uri/ /sub2/index.php?$query_string;
}
# [other sub-apps included in the same way]
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
# [ssl stuff]
}
我也试着用
location ^~ /(sub1|sub2)/ {
try_files $uri $uri/ /$1/index.php?$query_string;
}`
但没有成功-这个位置不知怎么不匹配,所有的东西都传给了
/index.php
而是在基地。