服务器上nginx配置文件问题

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        #root  /home/wwwroot/default;
        root /home/wwwroot/default/laravel-demo/public;
    }

以上是我的配置信息,但是访问 500
如果我把 root 去掉 public 在我的URL 访问 xxx.com/public 就可以访问。

谢谢,已经解决了! 我这边的问题是因为我使用的最新的lnmp1.4一键安装环境,nginx里面有个配置项出错了。

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

把这个注释掉就行了

JellyBool

location 的一些配置没对吧。你看看 https://www.laravist.com/series/deploy-laravel-app-on-vps

Perfect丶戈 回复 JellyBool

问题是我 root 要是 写 /home/wwwroot/default/laravel-demo 的话我域名后写 public 就可以访问…

JellyBool 回复 Perfect丶戈

要不你就贴全部的配置出来,不然我也不知道。我觉得还是 location 没配置好吧

Perfect丶戈 回复 JellyBool
server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        #root  /home/wwwroot/default;
        root /home/wwwroot/default/laravel-demo/public;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        include enable-php.conf;

        server_name localhost;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        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;
        }

        access_log  /home/wwwlogs/access.log;
    }

xiaowuya123 回复 JellyBool

他这个是网站设置了open_basedir ,用的是lnmp的一键安装包,在 enable-php.conf里面设置了open_basedir,注释掉就好! 或者修改增加vhost时的目录里面的 .user.ini 里面的open_basedir到项目根目录

JellyBool

基本上就是下面三个关键的配置:

        server_name your_domain;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php7.1-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

先看看视频吧

Perfect丶戈 回复 JellyBool

我找到问题了,不是nginx 配置问题,是 public/index.php 里面的 require DIR.’/…/bootstrap/autoload.php’;
DIR.’/…/bootstrap/app.php’;
好像引入找不到这文件- -

MarksGui888 回复 Perfect丶戈

怎么解决的? 我目前也遇到这个问题,好忧伤,从外层index.php进去就行,设置根目录为public/index.php就报500

xiaowuya123 回复 MarksGui888

这个问题是文件的权限不够(主要是bootstrap,storage这2个文件夹 ),给这2个文件夹增加nginx用户775权限就没问题.

xiaowuya123 回复 MarksGui888

如果给了权限还没解决,再看看你是不是设置了open_basedir 的访问目录

MarksGui888 回复 xiaowuya123

谢谢,已经解决了! 我这边的问题是因为我使用的最新的lnmp1.4一键安装环境,nginx里面有个配置项出错了。

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

把这个注释掉就行了