1.安全的配置(同一vps多站点)
2.友好的站点入口
部署问题重述: 由于thinkphp5经过重构,和thinkphp3.2有很大的不同,其中之前的入口文件index.php由/index.php改为/public/index.php, 那么问题来了:
1.如果按lnmp集成环境提供的方法(lnmp vhost add)添加虚拟站点,访问站点就要加个二级目录,如 https://xxx.com/public
所以为了可以让访问链接变得更加友好(即https://xxx.com),可以修改/usr/local/nginx/conf/vhost/xxx.com.conf,做以下修改
root /home/wwwroot/xxx.com/;改为:
root /home/wwwroot/xxx.com/public;那么问题来了,由于lnmp环境考虑到虚拟站点各自的访问目录权限问题,于是在/usr/local/nginx/conf/fastcgi.conf里配置了
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";那么每个站点的访问权限就限制在各自的document_root里了, 于是,我们修改的root(root /home/wwwroot/xxx.com/public;)就把权限限制在public目录之后, 软件架构根目录下的application等都无法访问了,那么此时我们要解决的问题是:
2.既要保持root/home/wwwroot/xxx.com/public;,又要让虚拟站点有/home/wwwroot/xxx.com目录的访问权限, 那么可以修改/usr/local/nginx/conf/fastcgi.conf配置文件:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";改为:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/xxx.com/:/tmp/:/proc/";但问题来了,/usr/local/nginx/conf/fastcgi.conf是公共配置文件,采用这种写死的方式会导致其他站点不可用,为了兼顾其他虚拟站点,if_not_empty派上用场了,修改方法为:
不改变/usr/local/nginx/conf/fastcgi.conf配置文件里的原配置,而在
fastcgi_paramPHP_ADMIN_VALUE"open_basedir=$document_root/:/tmp/:/proc/";
之后添加
fastcgi_param PHP_ADMIN_VALUE $basedir if_not_empty;#注意nginx要在1.1.11版本之后
$basedir变量就可以在/usr/local/nginx/conf/vhost/xxx.com.conf配置文件里的include enable-php.conf 前赋值:
set$basedir"open_basedir=/home/wwwroot/dev.yunshare.net/:/tmp/:/proc/";
优点:这样既满足了thinkphp5的部署要求,又不影响其他一般站点的使用。
缺点:如果$basedir没有赋值(至少一个专属配置有赋值),nginx -t无法通过。
注意rewrite规则:
最后献上thinkphp的rewrite规则:
这种写法3.2是可以的,但在这里是不可以的,否则经测试pathinfo为空
location / { try_files $uri $uri/ /index.php?$query_string; }应该改为:
location / { if (!-e $request_filename){ rewrite ^/(.*)$ /index.php?s=/$1 last; } }好了