我试图configurationnginx根据url使用两个不同的文档根,所以如果有人连接到www.example.com将从/ portal / public_html获得网站,但是如果客户端连接到www.example.com/account将得到从其他目录/门户网站2 /公共和该网站的网站应由PHP 7服务。我在nginxconfiguration中使用variables来实现我的目标,但东西不工作,因为我认为它应该。 我得到错误500.在我的日志中,我看到nginx正在他的默认目录“/ usr / share / nginx / html”寻找网站文件2017/11/20 10:31:38 [debug] 21729#0: *421789 fastcgi param: "DOCUMENT_ROOT: /usr/share/nginx/html
也许configuration会更简单,阅读和理解,然后我生锈的英语,所以这是我的nginxconfiguration:
服务器{
听81默认;
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;
位置 / {
设置$ my_root / portal / public_html;
#PHP v5
设置$ php_host_port 127.0.0.1:9000;
root / $ my_root;
index index.php;
proxy_read_timeout 200;
include / nginx_conf / portal_rewrite_params;
}
位置〜^ /(帐号|新车|login|注册| n){
设置$ my_root / portal2 / public;
根$ my_root;
proxy_read_timeout 200;
index index.php;
try_files $ uri $ uri / /index.php$is_args$args;
#PHP v7
设置$ php_host_port 127.0.0.1:9071;
}
位置〜\ .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;
}
}
所以我的问题如何实现该nginx从不同的文档根服务于同一网站,并使用不同的PHP取决于URL? 我的方法好吗?
我的环境是centos 7,nginx / 1.10.2,php 5.6和php7.1
你的变数令人困惑
root /portal/public_html; location ~^/(account|new-cart|signin|register|n) { root /portal2/public; index index.php; location ~* \.php { fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_pass 127.0.0.1:9071; # include other fascgi_params } } location / { try_files $uri $uri/ /index.php$is_args$args; } location ~* \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $document_root; # include other fascgi_params }