For developing purpose, my apps need to be tested on different version,
so my idea was to serve it in different url like this :
http://example.com/v3/
http://example.com/v4/
.....
http://example.com/v20/
http://example.com/v45/
my files/folder like this :
/var/www/
| apps/
| 3/public/index.php
| 4/public/index.php
....
| 20/public/index.php
| 45/public/index.php
using below configuration, i could make it work like expected
location /v3 {
alias /var/www/apps/3/public;
try_files $uri $uri/ @versioning;
include /var/local/config/php7.4.cnf;
}
location /v4 {
alias /var/www/apps/4/public;
try_files $uri $uri/ @versioning;
include /var/local/config/php7.4.cnf;
}
# ......
location /v25 {
alias /var/www/apps/25/public;
try_files $uri $uri/ @versioning;
include /var/local/config/php7.4.cnf;
}
# ......
location /v30 {
alias /var/www/apps/30/public;
try_files $uri $uri/ @versioning;
include /var/local/config/php7.4.cnf;
}
location @versioning {
rewrite ^/v([0-9]+)/(.*)$ /v$1/index.php/$2 last;
}
but, for every version release i need to alter the nginx.conf file.
Therefore I changed it to regex rewrite location with aliases
location ~ ^/v(?<version>[a-z0-9]*)/$ {
alias /var/www/apps/$version/public;
try_files $uri $uri/ @versioning;
include /var/local/config/php7.4.cnf;
}
location @versioning {
rewrite ^/v([0-9]+)/(.*)$ /v$1/index.php/$2 last;
}
using the later config return 404. am i missing something ?
nginx with debug, show following log :
[debug] *1 generic phase: 0
[debug] *1 rewrite phase: 1
[debug] *1 test location: "/"
[debug] *1 test location: ~ "\.php$"
[debug] *1 test location: ~ "/\.ht"
[debug] *1 test location: ~ "^/v(?<version>[a-z0-9]*)/$"
[debug] *1 http regex set $version to "3"
[debug] *1 test location: ~ "\.php$"
[debug] *1 using configuration "^/v(?<version>[a-z0-9]*)/$"
...
[debug] *1 try files handler
[debug] *1 http script copy: "/var/www/apps/"
[debug] *1 http script var: "3"
[debug] *1 http script copy: "/public"
[debug] *1 http script var: "/v3/"
[debug] *1 trying to use file: "/v3/" "/var/www/apps/3/public/v3/"
[debug] *1 add cleanup: 00005598627533A0
[debug] *1 malloc: 0000559862745E40:144
[debug] *1 malloc: 0000559862742430:27
[debug] *1 cached open file: /var/www/apps/3/public/v3/, fd:-1, c:0, e:2, u:1
[debug] *1 http script var: "/v3/"
[debug] *1 trying to use dir: "/v3/" "/var/www/apps/3/public/v3/"
[debug] *1 add cleanup: 00005598627533D8
[debug] *1 cached open file: /var/www/apps/3/public/v3/, fd:-1, c:0, e:2, u:2
[debug] *1 trying to use file: "@versioning" "/var/www/apps/3/public@versioning"
[debug] *1 test location: "@versioning"
[debug] *1 using location: @versioning "/v3/?"
[debug] *1 rewrite phase: 3
[debug] *1 http script regex: "^/v([0-9]+)/(.*)$"
[notice: *1 "^/v([0-9]+)/(.*)$" matches "/v3/", client: xx.192.153.44, server: _, request: "GET /v3/ HTTP/1.1", host: "xx.15.38.80"
[debug] *1 http script copy: "/v"
[debug] *1 http script capture: "3"
[debug] *1 http script copy: "/index.php"
[debug] *1 http script args
[debug] *1 http script copy: "/"
[debug] *1 http script capture: ""
[debug] *1 http script regex end
i think the problem is the path nginx look it up was wrong
[debug] *1 trying to use file: "/v3/" "/var/www/apps/3/public/v3/"
[debug] *1 cached open file: /var/www/apps/3/public/v3/, fd:-1, c:0, e:2, u:1
[debug] *1 trying to use dir: "/v3/" "/var/www/apps/3/public/v3/"
/var/www/apps/3/public/v3/
it append more v3
at the end, whereas it show the correct path /var/www/apps/3/public
if i use static rewrite.