我的开发人员将在本地计算机上编辑多个 Wordpress 站点。我想为他们设置一次 Nginx,而无需他们将来编辑配置文件。通常,当 Nginx 配置为托管 Wordpress 时,会包含如下位置块:
location / {
try_files $uri $uri/ /index.php$is_args$args;
} # End location
在我们的情况下,每个 WP 站点都将位于其自己的子目录中。因此,当开发人员需要查看网站时,他们会在浏览器中访问一个 URL,例如:
http://localhost/site1
http://localhost/site2
http://localhost/site3
我们希望上面的位置指令包含子目录。就像现在一样,它只包括根(http://localhost)而不是潜艇。我认为这需要某种通配符或正则表达式,但我不确定。
换句话说,我想我正在寻找一个像这样的位置块:
location /all-subdirectories {
try_files $uri $uri/ /whatever-subdirectory/index.php$is_args$args;
} # End location
这有意义还是我走错了路?
你可以使用正则表达式 location
捕获 URI 的第一部分,例如:
location ~ ^(/[^/]+) {
try_files $uri $uri/ $1/index.php?$args;
}
或者使用一个或多个命名位置rewrite
语句,例如:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^(/[^/]+) $1/index.php last;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)