nginx 部署 yii2项目
1.Linux 添加虚拟主机,访问目录绑定至 web目录下面,比如 bac/web2.更新配置文件,修改你自己的.conf文件,比如a.conf,我的是在 /usr/local/nginx/conf/vhost/目录下,然后添加location / {# Redirect everything that isn't a real file to index.php...
1.Linux 添加虚拟主机,访问目录绑定至 web目录下面,比如 bac/web
2.更新配置文件,修改你自己的.conf文件,比如a.conf,我的是在 /usr/local/nginx/conf/vhost/目录下,然后添加
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
3.重启下Nginx,centos的 直接service Nginx restart
4.然后访问你的域名。
5.有些小伙伴的可能会出错,可能会出现error 500的错误或者什么错误也不显示,不用慌,
error_reporting(E_ALL);
ini_set('display_errors', '1');
直接把这两行代码,放在你的web/index.php 里面,最上面,然后保存,再次访问,看错误。
6.
1)若错误是file_exists(): open_basedir restriction in effect.之类的。
2)不用怕,找到你的conf文件的上一级目录/usr/local/nginx/conf/,直接进入,找到fastcgi.conf 这个文件,
3)然后打开,找到fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";这一行,
修改为fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/www/:/tmp/:/proc/"; 只需要把$document_root,改为你项目的所在目录,比如:/home/wwwroot/然后保存,重启Nginx。注意:不是网站根目录,不要配置到Public下面!!!
7.重新访问,是不是可以了呢,喜欢的小伙伴,留言吧,或者联系QQ:3396475100或群:372319250,替你解决更多小烦恼哦!
8.若是报错 mkdir(): Permission denied,说明,没有权限 chmod -R 777 你的目录就行啦。
更多推荐
所有评论(0)