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;
}
}
任何想法?