Override PHP server variables like `REQUEST_URI`
I've used nginx-unit for standalone php servers in the past with great success so I decided to try and move a rather large production configuration of nginx + php-fpm to nginx + nginx-unit (php) but ran into what seems to be a limitation in the design. It seems that while nginx-unit supports sitting behind nginx, it doesn't really cater for cases where nginx is performing redirects for the app because it expects that php's $_SERVER['REQUEST_URI'] will come from $request_uri.
In this case, because I am porting a php-fpm installation to nginx-unit, nginx has already rewritten "virtual urls" to the actual document url. I thought I could use proxy_set_header X-Request-Uri $request_uri; in nginx to make a variable $header_x_request_uri available to nginx-unit and then configure nginx-unit to tell php to use $header_x_request_uri as REQUEST_URI but this does not seem possible (the only options are script and index?).
In an nginx + php-fpm installation, the nginx fastcgi_param directive can be used to set the following variables:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
but there doesn't seem to be any way to do the same in nginx-unit?
If you set X_REQUEST_URI in nginx (proxy), unit should forward that to PHP as-is, meaning you could easily make the first line in your index.php-file:
<?php
$_SERVER['REQUEST_URI'] = $_SERVER['X_REQUEST_URI'];
// Start app here
Or just adjust the app to use X_REQUEST_URI instead
Edit: Alternatively, you could restore the original path with routes and NJS, see https://unit.nginx.org/scripting/, e.g.:
{
"routes": {
"parse": [
{
"action": {
"rewrite": "`${ headers['X-Request-Path'] }`",
"pass": "routes/my-route"
}
}
]
}}
Alternatively, to just adjust the URL and then move on to the next rule
{
"routes": {
"parse": [
{
"action": {
"rewrite": "`${ headers['X-Request-Path'] }`",
"pass": "routes"
}
}
]
}}
Hello @scheibling, Thanks for your suggestion:
$_SERVER['REQUEST_URI'] = $_SERVER['X_REQUEST_URI'];
It works.
But if I want to use rewrite action, REQUEST_URI is not changed. This is my testbed
curl --unix-socket /var/run/unit/control.unit.sock http://localhost/config
{
"listeners": {
"*:9096": {
"pass": "routes/parse"
}
},
"routes": {
"parse": [
{
"action": {
"rewrite": "test_rewrite",
"pass": "applications/test"
}
}
]
},
"applications": {
"test": {
"type": "php",
"root": "/usr/local/nginxunit",
"script": "test.php"
}
}
}
test.php:
<?php
// error_log("XXXXXXXX");
header("Content-Type: application/json; charset=utf-8");
$r = array (
"message" => "Unit reporting",
"agent" => "NGINX Unit 1.34.2"
);
foreach ($_SERVER as $header => $value)
$r["headers"][$header] = $value;
$r["body"] = file_get_contents("php://input");
$r["sha256"] = hash("sha256", $r["body"]);
echo json_encode($r, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
# curl http://localhost:9096/testst
{
"message": "Unit reporting",
"agent": "NGINX Unit 1.34.2",
"headers": {
"SERVER_SOFTWARE": "Unit/1.34.1",
"SERVER_PROTOCOL": "HTTP/1.1",
"PHP_SELF": "/test.php",
"SCRIPT_NAME": "/test.php",
"SCRIPT_FILENAME": "/usr/local/nginxunit/test.php",
"DOCUMENT_ROOT": "/usr/local/nginxunit",
"REQUEST_METHOD": "GET",
"REQUEST_URI": "/testst",
"QUERY_STRING": "",
"REMOTE_ADDR": "127.0.0.1",
"SERVER_ADDR": "127.0.0.1",
"SERVER_NAME": "localhost",
"SERVER_PORT": "80",
"HTTP_HOST": "localhost:9096",
"HTTP_USER_AGENT": "curl/7.76.1",
"HTTP_ACCEPT": "*/*",
"REQUEST_TIME_FLOAT": 1747221928.3028628826141357421875,
"REQUEST_TIME": 1747221928
},
"body": "",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
Am I doing something wrong? Thank you.
@victorserbu2709 Could you include the actual content of the rewrite code? And which version of Unit are you using?
@scheibling
i tried rewriting also with njs. But it doesn't work even when trying with a static setting "rewrite": "/v1/test_rewrite"
{
"listeners": {
"*:9096": {
"pass": "routes/parse"
}
},
"routes": {
"parse": [
{
"action": {
"rewrite": "/v1/test_rewrite",
"pass": "applications/test"
}
}
]
},
"applications": {
"test": {
"type": "php",
"root": "/usr/local/nginxunit",
"script": "test.php"
}
}
}
[root@nginxunitlia nginxunit]# /usr/local/unit/sbin/unitd-debug --version
unit: [debug] sys_nerr: 132
unit: [debug] malloc(6820): 9B6330
unit: [debug] stderr flags: 0x0402
unit: [debug] ncpu: 8
unit: [debug] pagesize: 4096
unit: [debug] malloc(24): 9B7DE0
unit: [debug] malloc(3674): 9B7E00
unit: [debug] malloc(392): 9B8C70
2025/05/14 11:51:40.476 [debug] 244182#244182 realloc(0, 32): 9B8EB0
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(24): 9B9100
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(168): 9B8E00
2025/05/14 11:51:40.477 [debug] 244182#244182 posix_memalign(16, 584): 9B9120
2025/05/14 11:51:40.477 [debug] 244182#244182 pthread_mutex_init(9B9198)
2025/05/14 11:51:40.477 [debug] 244182#244182 posix_memalign(16, 832): 9B9370
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(136): 9B96C0
2025/05/14 11:51:40.477 [debug] 244182#244182 posix_memalign(128, 1024): 9B9780
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(1400): 9BA110
2025/05/14 11:51:40.477 [debug] 244182#244182 create engine 9BA110
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(16368): 9BA690
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(16368): 9BE690
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(160): 9B9C10
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(2048): 9C2690
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(384): 9B9CC0
2025/05/14 11:51:40.477 [debug] 244182#244182 epoll_create(): 3
2025/05/14 11:51:40.477 [debug] 244182#244182 signalfd(): 4
2025/05/14 11:51:40.477 [debug] 244182#244182 eventfd(): 5
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(2048): 9C2EA0
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(168): 9B9E50
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(136): 9B9F00
2025/05/14 11:51:40.477 [debug] 244182#244182 posix_memalign(128, 1024): 9C3700
2025/05/14 11:51:40.477 [debug] 244182#244182 malloc(232): 9B9F90
unit version: 1.34.1
configured as ./configure --prefix=/usr/local/unit --modulesdir=/usr/local/unit/lib64/unit/debug-modules --localstatedir=/var --libdir=/usr/local/unit/lib64 --cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -I./njs/src/ -I./njs/build/' --ld-opt='-Wl,-z,relro -Wl,-z,now -L./njs/build/' --user=unit --group=unit --openssl --njs --debug
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_wait(25): 1
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll: fd:18 ev:0001 d:7F0B30001430 rd:5 wr:0
2025/05/14 11:52:16.145 [debug] 242902#242908 timer expire minimum: 170035264:83782231
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: accept
2025/05/14 11:52:16.145 [debug] 242902#242908 accept4(18): 12
2025/05/14 11:52:16.145 [debug] 242902#242908 client: 127.0.0.1
2025/05/14 11:52:16.145 [debug] 242902#242908 malloc(168): 7F0B30002CA0
2025/05/14 11:52:16.145 [debug] 242902#242908 posix_memalign(16, 464): 7F0B30002D50
2025/05/14 11:52:16.145 [debug] 242902#242908 *51 connections: 2
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: accept
2025/05/14 11:52:16.145 [debug] 242902#242908 accept4(18) (11: Resource temporarily unavailable)
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: read
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 http conn init
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: read
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 conn read fd:12 rdy:0 cl:0 er:0 bl:0
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 epoll 25 set event: fd:12 op:1 ev:80002001
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 timer add: 0±50 180000:83962231
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 timer change: 83962231±50:1
2025/05/14 11:52:16.145 [debug] 242902#242908 timers changes: 1
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 timer rbtree insert: 83962231±50
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 timer found minimum: 83962231±50:83782231
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll 25 changes:1
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 epoll_ctl(25): fd:12 op:1 ev:80002001
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_wait(25) timeout:180000
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_wait(25): 1
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 epoll: fd:12 ev:0001 d:7F0B300015E0 rd:5 wr:0
2025/05/14 11:52:16.145 [debug] 242902#242908 timer expire minimum: 83962181:83782231
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: read
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 conn read fd:12 rdy:1 cl:0 er:0 bl:0
2025/05/14 11:52:16.145 [debug] 242902#242908 recvbuf: 0, 7F0B30002F78, 2048
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 recv(12, 7F0B30002F78, 2048, 0x0): 86
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 timer disable: 83962231
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 h1p conn proto init
2025/05/14 11:52:16.145 [debug] 242902#242908 malloc(136): 7F0B30006D80
2025/05/14 11:52:16.145 [debug] 242902#242908 posix_memalign(128, 1024): 7F0B30005B80
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 h1p conn request init
2025/05/14 11:52:16.145 [debug] 242902#242908 malloc(184): 7F0B30003D00
2025/05/14 11:52:16.145 [debug] 242902#242908 posix_memalign(16, 648): 7F0B30003DC0
2025/05/14 11:52:16.145 [debug] 242902#242908 malloc(232): 7F0B30004050
2025/05/14 11:52:16.145 [debug] 242902#242908 posix_memalign(128, 4096): 7F0B30007400
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 h1p conn header parse
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 timer disable: 83962231
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 h1p request body read -1 te:0
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 http application handler
2025/05/14 11:52:16.145 [debug] 242902#242908 posix_memalign(128, 128): 7F0B30006F00
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 rpc: stream #39 registered
2025/05/14 11:52:16.145 [debug] 242902#242908 mp 7F0B30003D00 retain: 2
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_lock(184F880) enter
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_unlock(184F880) exit
2025/05/14 11:52:16.145 [debug] 242902#242908 mp 7F0B30003D00 retain: 3
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 request 288 bytes shm buffer
2025/05/14 11:52:16.145 [debug] 242902#242908 mp 7F0B30000BB0 retain: 2
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_lock(184F9B8) enter
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_unlock(184F9B8) exit
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 outgoing mmap buf allocation: 7F0B30001900 [7F0B3EA69000,16384] 242902->0,0,0
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 fields_count=3
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 add field 0xE6EB, 0, 4, 7F0B30002F90 : 14 7F0B30002F96
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 add field 0x0220, 0, 10, 7F0B30002FA6 : 11 7F0B30002FB2
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 add field 0xD871, 0, 6, 7F0B30002FBF : 3 7F0B30002FC7
2025/05/14 11:52:16.145 [debug] 242902#242908 *50 about to send 288 bytes buffer to app process port 13
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_lock(1845FD0) enter
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_unlock(1845FD0) exit
2025/05/14 11:52:16.145 [debug] 242902#242908 sendmsg(13, -1, -1, 1): 16
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_wait(25) timeout:-1
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] poll(12,10): 1, revents [0000, 0001]
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] app_queue_recv: 28
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] #39: process message 23 fd[0] -1 fd[1] -1
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] #39: mmap_read: [0x7f0b2527f000,288] 242902->0,(0,0,288)
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] #39: GET /test.php (0)
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] check_response_port: found port{242902,2}
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] port{242902,2} enqueue 16 notify 1
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] sendmsg(11, 16, 0): 16
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] port{242902,2} send 16 read_queue
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] #39: PHP execute script /usr/local/nginxunit/test.php
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_wait(25): 1
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll: fd:44 ev:0001 d:7F0B30000D20 rd:5 wr:0
2025/05/14 11:52:16.145 [debug] 242902#242908 timer expire minimum: 170182231:83782231
2025/05/14 11:52:16.145 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.145 [debug] 242902#242908 port{242902,2} 44: dequeue 16
2025/05/14 11:52:16.145 [debug] 242902#242908 port 44: message type:24 fds:16,0
2025/05/14 11:52:16.145 [debug] 242902#242908 rpc: stream #39 handler, type 24
2025/05/14 11:52:16.145 [debug] 242902#242908 stream #39: got ack from 243352:0
2025/05/14 11:52:16.145 [debug] 242902#242908 posix_memalign(128, 128): 7F0B30007180
2025/05/14 11:52:16.146 [debug] 243352#243352 [unit] #39: nxt_php_read_cookies
2025/05/14 11:52:16.145 [debug] 242902#242908 rpc: stream #39 assigned uniq pid 243352 (7F0B30001088)
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_lock(184F880) enter
2025/05/14 11:52:16.145 [debug] 242902#242908 process port (243352, 0) found
2025/05/14 11:52:16.145 [debug] 242902#242908 app 'test' move port 243352:0 out of spare_ports (ack)
2025/05/14 11:52:16.145 [debug] 242902#242908 pthread_mutex_unlock(184F880) exit
2025/05/14 11:52:16.145 [debug] 242902#242908 mp 7F0B30003D00 release: 2
2025/05/14 11:52:16.145 [debug] 242902#242908 port{242902,2} 44: dequeue -1
2025/05/14 11:52:16.145 [debug] 242902#242908 recvmsg(44, 2, 32): 16
2025/05/14 11:52:16.145 [debug] 242902#242908 port{242902,2} 44: recv 16 read_queue
2025/05/14 11:52:16.145 [debug] 242902#242908 port{242902,2} 44: dequeue -1
2025/05/14 11:52:16.145 [debug] 242902#242908 recvmsg(44, 2, 32): -1
2025/05/14 11:52:16.145 [debug] 242902#242908 recvmsg(44) not ready
2025/05/14 11:52:16.145 [debug] 242902#242908 port{242902,2} 44: recvmsg -2
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll 25 set event: fd:44 op:3 ev:80002001
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll 25 changes:1
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_ctl(25): fd:44 op:3 ev:80002001
2025/05/14 11:52:16.145 [debug] 242902#242908 epoll_wait(25) timeout:-1
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: nxt_php_register_variables
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register SERVER_PROTOCOL='HTTP/1.1'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register PHP_SELF='/test.php'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register SCRIPT_NAME='/test.php'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register SCRIPT_FILENAME='/usr/local/nginxunit/test.php'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register DOCUMENT_ROOT='/usr/local/nginxunit'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register REQUEST_METHOD='GET'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register REQUEST_URI='/test.php'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register QUERY_STRING=''
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register REMOTE_ADDR='127.0.0.1'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register SERVER_ADDR='127.0.0.1'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register SERVER_NAME='localhost'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register SERVER_PORT='80'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register HTTP_HOST='localhost:9096'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register HTTP_USER_AGENT='curl/7.76.1'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: php: register HTTP_ACCEPT='*/*'
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: nxt_php_read_post 8192
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: nxt_php_send_headers
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: init: 200, max fields 1/45
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: response_buf_alloc: 87
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] outgoing plain buffer allocation: (0x1bd2b20, 87)
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: add_field #0: Content-Type: application/json; charset=utf-8
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: send: 1 fields, 85 bytes
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: send plain: 101
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] port{242902,2} enqueue 1 read_socket notify 1
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] sendmsg(11, 101, 0): 101
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] port{242902,2} sendmsg 101
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll_wait(25): 1
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: write: 909
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll: fd:44 ev:0001 d:7F0B30000D20 rd:5 wr:0
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] outgoing plain buffer allocation: (0x7ffe682ff6c0, 909)
2025/05/14 11:52:16.146 [debug] 242902#242908 timer expire minimum: 170182231:83782232
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: send plain: 925
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] port{242902,2} enqueue 1 read_socket notify 0
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: dequeue 1 read_socket 1
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] sendmsg(11, 925, 0): 925
2025/05/14 11:52:16.146 [debug] 242902#242908 recvmsg(44, 2, 32): 101
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] port{242902,2} sendmsg 925
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: recvmsg 101
2025/05/14 11:52:16.146 [debug] 242902#242908 port 44: message type:27 fds:-1,-1
2025/05/14 11:52:16.146 [debug] 242902#242908 rpc: stream #39 handler, type 27
2025/05/14 11:52:16.146 [debug] 242902#242908 header: Content-Type: application/json; charset=utf-8
2025/05/14 11:52:16.146 [debug] 242902#242908 h1p request header send
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 retain: 3
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] #39: done: 0
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: dequeue 1 read_socket 1
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] port{242902,2} enqueue 16 notify 0
2025/05/14 11:52:16.146 [debug] 242902#242908 posix_memalign(16, 16496): 7F0B3000C740
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] app_queue_recv: -1
2025/05/14 11:52:16.146 [debug] 242902#242908 recvmsg(44, 2, 32): 925
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] poll(12,10): 1, revents [0000, 0001]
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: recvmsg 925
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] app_queue_recv: -1
2025/05/14 11:52:16.146 [debug] 242902#242908 port 44: message type:27 fds:-1,-1
2025/05/14 11:52:16.146 [debug] 242902#242908 rpc: stream #39 handler, type 27
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] recvmsg(10): 16
2025/05/14 11:52:16.146 [debug] 242902#242908 h1p request send
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] port{243352,65535} recv 16 read_queue
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 retain: 4
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] app_queue_recv: -1
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: dequeue 16
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] recvmsg(10) failed: Resource temporarily unavailable (11)
2025/05/14 11:52:16.146 [debug] 242902#242908 posix_memalign(16, 16496): 7F0B300107C0
2025/05/14 11:52:16.147 [debug] 243352#243352 [unit] app_queue_recv: -1
2025/05/14 11:52:16.146 [debug] 242902#242908 port 44: message type:27 fds:-1,-1
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30006F00)
2025/05/14 11:52:16.146 [debug] 242902#242908 rpc: stream #39 last handler, type 27
2025/05/14 11:52:16.146 [debug] 242902#242908 router data create last buf
2025/05/14 11:52:16.146 [debug] 242902#242908 mmap buf completion: 7F0B30001900 [7F0B3EA69000,16384] (sent=1), 242902->0,0,1
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30000BB0 release: 1
2025/05/14 11:52:16.146 [debug] 242902#242908 app 'test' release port 243352:0: -1 1
2025/05/14 11:52:16.146 [debug] 242902#242908 pthread_mutex_lock(184F880) enter
2025/05/14 11:52:16.146 [debug] 242902#242908 app 'test' move port 243352:0 to spare_ports
2025/05/14 11:52:16.146 [debug] 242902#242908 pthread_mutex_unlock(184F880) exit
2025/05/14 11:52:16.146 [debug] 242902#242908 app 'test' 184F880 requests queue is empty, keep the port
2025/05/14 11:52:16.146 [debug] 242902#242908 timer add: 0±50 0:83782232
2025/05/14 11:52:16.146 [debug] 242902#242908 timer change: 83782232±50:1
2025/05/14 11:52:16.146 [debug] 242902#242908 pthread_mutex_lock(184F880) enter
2025/05/14 11:52:16.146 [debug] 242902#242908 pthread_mutex_unlock(184F880) exit
2025/05/14 11:52:16.146 [debug] 242902#242908 h1p request send
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 retain: 5
2025/05/14 11:52:16.146 [debug] 242902#242908 rpc: stream #39 remove first and last pid 243352 registration (7F0B30001088)
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30007180)
2025/05/14 11:52:16.146 [debug] 242902#242908 rpc: stream #39 free registration
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: dequeue -1
2025/05/14 11:52:16.146 [debug] 242902#242908 recvmsg(44, 2, 32): -1
2025/05/14 11:52:16.146 [debug] 242902#242908 recvmsg(44) not ready
2025/05/14 11:52:16.146 [debug] 242902#242908 port{242902,2} 44: recvmsg -2
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll 25 set event: fd:44 op:3 ev:80002001
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 buf completion: 7F0B30017800 7F0B30017848
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30017800)
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: write
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 conn write fd:12 er:0 bl:0
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 sendbuf: 0, 7F0B30007A48, 150
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 sendbuf: 1, 7F0B30007C48, 7
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 sendbuf: 2, 7F0B3000C788, 909
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 sendbuf: 3, 7F0B30007CC8, 7
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 writev(12, 4): 1073
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 event conn: 1073 sent:1073
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 timer disable: 0
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 h1p conn sent
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 release: 4
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 release: 3
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 release: 2
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 buf completion: 7F0B3000C740 7F0B3000C788
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B3000C740)
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 router http request done (rpc_data 0)
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 http request close handler
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 h1p request close
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 conf joint 1848240 count: 2
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 h1p keepalive
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 setsockopt(12, 6, TCP_NODELAY): 1
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 h1p complete buffers
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 buf completion: 7F0B30002F30 7F0B30002F78
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 release: 1
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: read
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 conn read fd:12 rdy:0 cl:0 er:0 bl:0
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 timer add: 83962231±50 180000:83962232
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 timer previous: 83962232±50
2025/05/14 11:52:16.146 [debug] 242902#242908 timers changes: 1
2025/05/14 11:52:16.146 [debug] 242902#242908 timer rbtree insert: 83782232±50
2025/05/14 11:52:16.146 [debug] 242902#242908 timer found minimum: 83782232±50:83782232
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll 25 changes:1
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll_ctl(25): fd:44 op:3 ev:80002001
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll_wait(25) timeout:0
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll_wait(25): 0
2025/05/14 11:52:16.146 [debug] 242902#242908 timer expire minimum: 83782182:83782232
2025/05/14 11:52:16.146 [debug] 242902#242908 timer expire delete: 83782232±50
2025/05/14 11:52:16.146 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.146 [debug] 242902#242908 http request pool release
2025/05/14 11:52:16.146 [debug] 242902#242908 mp 7F0B30003D00 release: 0
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30003DC0)
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30004050)
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30007400)
2025/05/14 11:52:16.146 [debug] 242902#242908 free(7F0B30003D00)
2025/05/14 11:52:16.146 [debug] 242902#242908 *50 timer found minimum: 83962231±50:83782232
2025/05/14 11:52:16.146 [debug] 242902#242908 epoll_wait(25) timeout:179999
2025/05/14 11:52:16.147 [debug] 242902#242908 epoll_wait(25): 1
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 epoll: fd:12 ev:2001 d:7F0B300015E0 rd:5 wr:0
2025/05/14 11:52:16.147 [debug] 242902#242908 timer expire minimum: 83962181:83782233
2025/05/14 11:52:16.147 [debug] 242902#242908 work queue: read
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 conn read fd:12 rdy:1 cl:0 er:0 bl:0
2025/05/14 11:52:16.147 [debug] 242902#242908 recvbuf: 0, 7F0B30002F78, 2048
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 recv(12, 7F0B30002F78, 2048, 0x0): 0
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer disable: 83962231
2025/05/14 11:52:16.147 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 h1p conn close
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 h1p shutdown
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 h1p complete buffers
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 h1p closing
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 h1p conn closing
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 conn close fd:12, to:0
2025/05/14 11:52:16.147 [debug] 242902#242908 work queue: close
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 conn close handler fd:12
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer delete: 83962231±50
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer change: 0±50:2
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer delete: 0±50
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 epoll 25 set event: fd:12 op:2 ev:0
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer add: 0±50 0:83782233
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer change: 83782233±50:1
2025/05/14 11:52:16.147 [debug] 242902#242908 timers changes: 2
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer rbtree delete: 83962231±50
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer rbtree insert: 83782233±50
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer found minimum: 83782233±50:83782233
2025/05/14 11:52:16.147 [debug] 242902#242908 epoll 25 changes:1
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 epoll_ctl(25): fd:12 op:2 ev:0
2025/05/14 11:52:16.147 [debug] 242902#242908 epoll_wait(25) timeout:0
2025/05/14 11:52:16.147 [debug] 242902#242908 epoll_wait(25): 0
2025/05/14 11:52:16.147 [debug] 242902#242908 timer expire minimum: 83782183:83782233
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 timer expire delete: 83782233±50
2025/05/14 11:52:16.147 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 conn close timer handler fd:12
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 socket close(12)
2025/05/14 11:52:16.147 [debug] 242902#242908 work queue: fast
2025/05/14 11:52:16.147 [debug] 242902#242908 *50 h1p conn free
2025/05/14 11:52:16.147 [debug] 242902#242908 mp 7F0B3000C690 release: 0
2025/05/14 11:52:16.147 [debug] 242902#242908 free(7F0B300015E0)
2025/05/14 11:52:16.147 [debug] 242902#242908 free(7F0B30006D80)
2025/05/14 11:52:16.147 [debug] 242902#242908 free(7F0B30005B80)
2025/05/14 11:52:16.147 [debug] 242902#242908 free(7F0B3000C690)
2025/05/14 11:52:16.147 [debug] 242902#242908 listen event count: 2
2025/05/14 11:52:16.147 [debug] 242902#242908 epoll_wait(25) timeout:-1
Thank you
@victorserbu2709 That is weird, I'm trying the (almost) exact same config as you and it works for me. Just to double-check, are you pushing the changes to the config endpoint and getting a "Reconfiguration done"?
I am running Unit 1.30.0 though, I'll have to try compiling 1.34.1 to see if that breaks it, in that case this would be a bug
{
"listeners": {
"*:7899": {
"pass": "routes/parse"
}
},
"routes": {
"parse": [
{
"action": {
"rewrite": "/v1/test_rewrite",
"pass": "applications/test"
}
}
]
},
"applications": {
"test": {
"type": "php",
"root": "/app",
"script": "index.php"
}
}
}
index.php is just a print_r of the $_SERVER var:
Array
(
[SERVER_SOFTWARE] => Unit/1.30.0
[SERVER_PROTOCOL] => HTTP/1.1
[PHP_SELF] => /index.php
[SCRIPT_NAME] => /index.php
[SCRIPT_FILENAME] => /app/index.php
[DOCUMENT_ROOT] => /app
[REQUEST_METHOD] => GET
[REQUEST_URI] => /v1/test_rewrite
[QUERY_STRING] =>
[REMOTE_ADDR] => 172.19.0.1
[SERVER_ADDR] => 172.19.0.2
[SERVER_NAME] => localhost
[SERVER_PORT] => 80
[HTTP_HOST] => localhost:7899
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip, deflate, br, zstd
[HTTP_SEC_GPC] => 1
[HTTP_CONNECTION] => keep-alive
[HTTP_COOKIE] => session=jf6R27NZT1JVQf2jXrfh4gsvEwX95aOVrgtxHDQnSqVFw98GahL2FYnc1zyitIWT; Tilt-Token=20ce6555-becd-44ea-a5a6-0f74a696a17f; nonce=y2a9yaaLSBm2I1jA
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_SEC_FETCH_DEST] => document
[HTTP_SEC_FETCH_MODE] => navigate
[HTTP_SEC_FETCH_SITE] => none
[HTTP_SEC_FETCH_USER] => ?1
[HTTP_PRIORITY] => u=0, i
[HTTP_PRAGMA] => no-cache
[HTTP_CACHE_CONTROL] => no-cache
[REQUEST_TIME_FLOAT] => 1747233119.1164
[REQUEST_TIME] => 1747233119
[argv] => Array
(
)
[argc] => 0
)
You could test it with one of my builds, docker.io/cloudyne/php-unit:8.3-alpine, that's what I'm running with. Not sure if the version you're running is compiled with all the same arguments
@victorserbu2709 Quick edit, seems this broke between 1.30.0 and 1.34.3, let me look into it
Looks like the option to modify the REQUEST_URI for application routes has been removed, see https://github.com/nginx/unit/commit/87077ec4ba9a59f3332c3758a3c39a5c149025e5