前提
准备
一个 ThinkPHP 项目 test
上传服务器,在目录 /home/wwwroot
下
添加虚拟主机(网站)
$ sudo lnmp vhost add
修改站点配置
打开 .user.ini
$ cd /home/wwwroot/test/public
$ sudo chattr -i .user.ini
去掉文件中的 public
,最终如下:
open_basedir=/home/wwwroot/test:/tmp/:/proc/
添加文件保护:
$ sudo chattr +i .user.ini
运行目录添加权限:
$ cd ../
$ sudo chmod 777 public
$ sudo chmod 777 -R runtime
Nginx 配置
修改 fastcgi.conf
$ cd /usr/local/nginx/conf
$ sudo vi fastcgi.conf
注释掉下面这句话:
# fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
修改 test.cnguu.cn.conf
$ cd vhost
$ sudo vi test.cnguu.cn.conf
修改内容如下:
server
{
listen 80;
server_name test.cnguu.cn;
return 301 https://test.cnguu.cn$request_uri;
}
server
{
listen 443 ssl http2;
server_name test.cnguu.cn;
index index.html index.php;
root /home/wwwroot/test/public;
include ssl.conf;
include rewrite/thinkphp.conf;
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}