make virtual host with multiple php version
web example with YII2 Advanced
=========================================================
server {
listen 8107; # listen for IPv4
#listen [::]:80 ipv6only=on; # listen for IPv6
server_name localhost;
set $root_path /home/www/html/test;
root $root_path;
#access_log off;
#error_log /dev/null crit;
charset utf-8;
client_max_body_size 2048M;
location / {
root $root_path/frontend/web;
try_files $uri /frontend/web/index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /frontend/web$uri =404;
# check the www.conf file to see if PHP-FPM is listening on a socket or port
#fastcgi_pass 127.0.0.1:9000; # listen for a port
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # listen for a socket
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $root_path$fastcgi_script_name;
}
#avoid processing of calls to non-existing static files by Yii (uncomment if necessary)
location ~ \.(css|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar)$ {
access_log off;
log_not_found off;
try_files $uri /frontend/web$uri =404;
}
#location ~* \.(htaccess|htpasswd|svn|git) {
# deny all;
#}
location /root {
alias $root_path/backend/web;
try_files $uri /backend/web/index.php$is_args$args;
# redirect to the page without a trailing slash (uncomment if necessary)
#location = /admin/ {
# return 301 /admin;
#}
location ~ ^/root/(.+\.php)$ {
try_files $uri /backend/web/$1$is_args$args;
# check the www.conf file to see if PHP-FPM is listening on a socket or port
#fastcgi_pass 127.0.0.1:9000; # listen for a port
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # listen for a socket
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $root_path$1;
}
#avoid processing of calls to non-existing static files by Yii (uncomment if necessary)
location ~ ^/root/(.+\.(css|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar))$ {
try_files $uri /backend/web/$1$is_args$args;
}
}
}
=========================================================