0
我有這樣一個nginx的服務器配置:如何在Nginx服務器塊中使用匹配的位置作爲變量?
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
location /project1/public {
try_files $uri $uri/ /project1/public/index.php?$query_string;
}
location /project2/public {
try_files $uri $uri/ /project2/public/index.php?$query_string;
}
location /project3/public {
try_files $uri $uri/ /project3/public/index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
和它的作品。但是當我嘗試使用正則表達式(下面的代碼)來動態執行此操作時,它會下載URL而不是在瀏覽器中顯示它。
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
location ~ ^/([^/]+)/public {
try_files $uri $uri/ /$1/public/index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
任何想法?