我有一个开发服务器,我上传客户端网站,每个WordPress网站都有自己的数据库和目录(每个网站都是独立的)。我有一个服务器块。我的问题在于非常永久链接,这对我有用:
server_name dev.example.tld;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location / {
try_files $uri $uri/ =404;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-$
expires off;
}
location /site_1/ {
index index.php;
try_files $uri $uri/ /site_1/index.php?$args;
}
location /site_2/ {
index index.php;
try_files $uri $uri/ /site_2/index.php?$args;
}
我一直在寻找一种方法,而不是为每个网站添加位置块,但没有运气。
答案 0 :(得分:1)
您可以将location
更改为正则表达式并捕获网站名称:
location ~ ^(?<site>/[^/]+) {
try_files $uri $uri/ $site/index.php?$args;
}
或者,通过使用重写来实现相同的效果:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^(/[^/]+) $1/index.php last;
return 404;
}