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 你的目錄就行啦。