我想在ISPconfig上为子域做一个自定义rewrite
。当我添加下面的代码时,子域会重定向到主域。
样本#1:
server {
...
if ($http_host = "panel.example.com") {
rewrite ^(?!/(_SubDomains/Panel|stats|.well-known/acme-challenge))/(.*)$ /_SubDomains/Panel/$2 last;
rewrite ^/(.*)/(.*)$ /index.php?cmd=$1&scd=$2? last;
}
...
}
如果我像示例2中那样做,Nginx服务器将无法工作。
样本#2:
server {
...
if ($http_host = "panel.example.com") {
rewrite ^(?!/(_SubDomains/Panel|stats|.well-known/acme-challenge))/(.*)$ /_SubDomains/Panel/$2 last;
location ~ .php$ {
rewrite ^/(.*)/(.*)$ /index.php?cmd=$1&scd=$2? last;
}
}
...
}
如何进行子域特定的重写?
您应该为不同的子域创建单独的服务器块:
server {
...
server_name foo.example.com;
...
}
server {
...
server_name bar.example.com;
...
}