I have a website which is built on Codeigniter 3. It is a typical nginx + php-fpm setup. Now I need to direct some of the requests to be handled by another php-fpm pool. Here is a simplified example of the configuration:
nginx configuration
test.conf:
server {
server_name example.com;
root /var/www/ci;
index index.html index.php;
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
# Somehow send all requests starting with /test/ to /index.php
# but use 127.0.0.1:9001 instead of the default 127.0.0.1:9000
#location /test/ {
# ...
#}
location / {
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
php-fpm configuration
www1.conf:
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
www2.conf:
[www2]
user = www-data
group = www-data
listen = 127.0.0.1:9001
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 5
How can I tell nginx to send every request starting with /test/
to the other pool (www2)?
Examples
- http://example.com/hello/world should still go to pool www1
- http://example.com/test/something should go to pool www2