unit icon indicating copy to clipboard operation
unit copied to clipboard

rewrite works twice when passing to application target and $host used in target's name

Open veremax opened this issue 1 year ago • 2 comments

Hello! I am using Unit 1.31.1 with php 8.2 on Debian.

Seems, that I caught error in Unit's rewrite engine.

Rewrite running twice when passing to application target and $host variable is used in target name.

Example:

{
	"match": {
		"uri": [ "*.css", "*.js", "*.html" ]
	},
	"action": {
		"share": "/var/www/${host}/public${uri}",
		"chroot": "/var/www/${host}/public/",
		"response_headers": {
			"Content-Type": "${response_header_content_type}; charset=utf-8",
			"Cache-Control": "`${ uri.endsWith('.html') ? 'max-age=0' : 'max-age=86400, immutable' }`"
		},
		"fallback": {
			"rewrite": "/404${uri}",
			"pass": "applications/php82/${host}-40x"
		}
	}
}

If I request some non-existent file /abc.html, php target gets /404/404/abc.html as $_SERVER['REQUEST_URI'].

This is a log:

2024/01/12 00:25:59 [notice] 1946#1952 *10 "fallback" taken
2024/01/12 00:25:59 [notice] 1946#1952 *10 URI rewritten to "/404/abc.html"
2024/01/12 00:25:59 [notice] 1946#1952 *10 URI rewritten to "/404/404/abc.html"
2024/01/12 00:25:59 [info] 1960#1960 "php82" application started

If I remove variable $host from application target name and hardcode the host name, all works OK.

veremax avatar Jan 11 '24 22:01 veremax