【问题标题】:Laravel 502 bad gateway in Ubuntu LEMP stackUbuntu LEMP 堆栈中的 Laravel 502 错误网关
【发布时间】:2019-03-25 04:03:07
【问题描述】:

我无法访问我的 laravel 项目

我的 laravel 项目在 /var/www

我用这种方式更新了 nginx:

 server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/laravel/public;

    index index.php  index.html index.htm;

    server_name dev-localserve.co;

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

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;

            fastcgi_pass 127.0.0.1:9000;
    }

    location ~ /\.ht {
            deny all;
    }
}

我该如何解决这个问题?

【问题讨论】:

  • 检查/var/log/nginx/error.log
  • 它说“var/www/html的目录索引被禁止
  • 那么用户 nginx 进程正在运行,对该文件夹没有权限,添加它们。
  • 如何添加权限?对不起,我是 ubuntu 的新手 :(
  • 您应该正确查看权限,以及您需要哪些权限。比如,nginx 在哪个用户下运行?是否有对该文件夹具有权限的组? 'nginx' 是该组的成员吗?

标签: php laravel ubuntu nginx


【解决方案1】:

由于它是 Ubuntu 存储库,我相信你有 www-data 用户。运行这两个命令:

// For setting ownership
chown -R www-data:www-data /var/www/laravel

// For setting permissions
chmod 775 -R /var/www/laravel

另外,我认为您的 nginx 配置可能需要更多:

location ~ \.php$ { 
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/run/php/php7.2-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
       #fastcgi_read_timeout 1800; // this line maybe
}

【讨论】:

  • 谢谢,但现在我收到错误 403 禁止。
  • 检查您的登录/var/log/nginx/
猜你喜欢
  • 2021-10-23
  • 2014-11-20
  • 2019-08-16
  • 2018-05-05
  • 2017-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-06
相关资源
最近更新 更多