📜 ⬆️ ⬇️

A bunch of Nginx + Apache, how to give Apache only PHP requests?

The task was set: to make a fault-tolerant and productive web server. On the Internet, you can find a large amount of documentation on setting up a bundle of Nginx + Apache, it makes no sense to describe the whole technology. The idea is that the lightweight Nginx should give all the static content (images, archives, etc.), requests for the generation of dynamic content are given to the heavyweight Indian Apache. Such a bundle unloads the server and is now used almost everywhere.

How to give Apache ONLY requests for PHP, and everything else to handle NGINX `th?

In the official documentation , as in the rest, do this:
')
server {
listen one.example.com;
server_name one.example.com

location / {
proxy_pass http://127.0.0.1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}

location ~* \.(jpg|jpeg|gif|html)$ {
root /spool/www;
access_log off;
expires 30d;
}
}


those. list all the file formats that NGINX will handle, everything else flies away through proxy_pass http://127.0.0.1/ . Enumerate all possible options extensions impossible. A little conjuring with a regular expression we get this:

server {
listen one.example.com;
server_name one.example.com

location / {
proxy_pass http://127.0.0.1/;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr

}

location ~* \.(?!(php|php5|phps)$)[^.]*[^\/]$ {
root /usr/local/www/one.example.com/;
}


those. processing of all files that do NOT end in .php, .php5, phps or address does not end with "/" is given to NGINX, php and the Indian processes the roots.

upd: lomik suggested a more rational solution:
server {
listen one.example.com;
server_name one.example.com

location / {
root /usr/local/www/one.example.com/;
index index.php index.html index.htm;
}

location ~ \.php {
proxy_pass http://127.0.0.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}

Source: https://habr.com/ru/post/83897/


All Articles