私はこのような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;
}
}
をし、それが動作します。しかし、これを動的に行うためにregex(以下のコード)を使用しようとすると、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;
}
}