I'm trying to configure nginx to use two different document root depending on url, so if some one connects to www.example.com will get site from /portal/public_html but if client connect to www.example.com/account will get sites from other directory /portal2/public and that site should be served by php 7.
I'm using variables in nginx configuration to achieve my goal, but something is not working as I thought it should. I'm getting errors 500. In my logs I see that nginx is looking for site files in his default directory "/usr/share/nginx/html"
2017/11/20 10:31:38 [debug] 21729#0: *421789 fastcgi param: "DOCUMENT_ROOT: /usr/share/nginx/html
Maybe the configuration will be simpler to read and understand then my rusty english so this is my nginx configuration:
server { listen 81 default; server_name www.example.com; access_log /var/log/nginx/www.example.com.access.log; error_log /var/log/nginx/www.example.com.error.log debug; location / { set $my_root /portal/public_html; #PHP v5 set $php_host_port 127.0.0.1:9000; root /$my_root; index index.php; proxy_read_timeout 200; include /nginx_conf/portal_rewrite_params; } location ~^/(account|new-cart|signin|register|n) { set $my_root /portal2/public; root $my_root; proxy_read_timeout 200; index index.php; try_files $uri $uri/ /index.php$is_args$args; #PHP v7 set $php_host_port 127.0.0.1:9071; } location ~ \.php$ { fastcgi_pass $php_host_port; fastcgi_index index.php; include /nginx_conf/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $document_root; } }
So my question how to achieve that nginx serve same site from different document root and using different php depending on URL? Is my approach good ?
My enviroment is centos 7, nginx/1.10.2, php 5.6 and php7.1