If browsing web.dev/test2
, it will look into /var/www/testsite/test2.local/public
. All done through local proxy.
Below rewrite running perfectly for test2
only:
upstream site.local {
server 127.0.0.1;
}
server {
server_name web.dev;
root /var/www/web.dev/public;
index index.php;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location /test2 {
proxy_pass http://site.local/;
}
}
server {
server_name site.local;
root /var/www/testsite/test2.local/public;
index index.php;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
I have hundreds of /test3
, /test4
, and so on. I don't want to write individual server
directive for each of them because it will be too long and tedious.
Below is what I've done so far to do wildcard:
upstream *.local {
server 127.0.0.1;
}
server {
server_name web.dev;
root /var/www/web.dev/public;
index index.php;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location /(?<mytestsite>[^/]+) {
proxy_pass http://$mytestsite.local/;
}
}
server {
server_name *.local;
root /var/www/testsite/$host/public;
index index.php;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
It won't work. upstream
won't accept wildcard. Use regex .*
on upstream
also not works.