當你將默認的訪問路徑改後(nginx.conf中的root 之後的路徑),同時應該將/home/wwwroot/default/.user.ini 中的路徑也改了!
.user.ini 是隱藏文件,需要 ls -a 查看;
第一步:你先確定你的pathinfo路由開啓了,配置如下:
lnmp v1.1上,修改對應虛擬主機的配置文件(/usr/local/nginx/conf/vhost/域名.conf)
去掉#include pathinfo.conf前面的#,把try_files $uri =404; 前面加上# 註釋掉。
1.2,1.3上,修改對應虛擬主機的配置文件(/usr/local/nginx/conf/nginx.conf)將include enable-php.conf;替換爲include enable-php-pathinfo.conf;
修改pathinfo需要重啓nginx生效。
第二步:路由重寫設置成功
server {
listen 80;
server_name www.aaa.com;
root "你的項目路徑";
include enable-php-pathinfo.conf;//開啓pathinfo
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
location ~ /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
fastcgi_param APPLICATION_ENV dev;
}
location / {
index index.html index.htm index.php l.php;
autoindex on;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
第三步:再次訪問,如果是500/空白頁面
在你框架index.php開頭,打開報錯,如下:
error_reporting(E_ALL);
默認是沒有開啓報錯的,設置如下:
1、先打開php的錯誤提示
將 php.ini中的 display_errors = Off 修改爲 On;
2、開啓nginx的報錯
在 /usr/local/php/etc/php-fpm.conf 加上
php_admin_value[error_log] = /usr/local/php/var/log/php_errors.logphp_admin_flag[log_errors] = on
有時可能錯誤日誌文件不自動創建,可以執行:touch /usr/local/php/var/log/php_errors.log && chown www:www /usr/local/php/var/log/php_errors.log
然後你訪問,會得到以下的報錯:
- PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/default/laravel/bootstrap/autoload.php) is not within the allowed path(s): (/home/wwwroot/default/laravel/public:/tmp/:/var/tmp/:/proc/) in /home/wwwroot/default/laravel/public/index.php on line 22
- PHP Warning: require(/home/wwwroot/default/laravel/bootstrap/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/default/laravel/public/index.php on line 22
- PHP Fatal error: require(): Failed opening required ‘/home/wwwroot/default/laravel/public/../bootstrap/autoload.php‘ (include_path=‘.:/usr/local/php/lib/php‘) in /home/wwwroot/default/laravel/public/index.php on line 22
如果這樣還是報錯的話,那就改爲 fastcgi_param PHP_ADMIN_VALUE "open_basedir=NULL";
這樣的話你就應該可以訪問到項目了!!!