【问题标题】:Serving empty blank page without errors提供没有错误的空白页
【发布时间】:2018-08-19 22:38:35
【问题描述】:

第一次这样做。自从我遇到这个问题两天后,还没有找到问题所在。

我在EC2 上的Ubuntu 18.04 实例上安装了laravel。该项目在我当地的Homestead 环境中运行良好。经过与权限的斗争,我现在被nginx/laravel提供的空白页面困住了。

我希望设置权限,以便用户ubuntu 可以从BitBucket 部署更新,而www-data 可以运行Laravel 应用程序。

我被困住了,因为我似乎无法找到记录/发生错误的位置。

几点;

  1. 网站的nginx 错误日志中没有错误

  2. Nginx 在站点的访问日志中显示 HTTP 200 响应代码

  3. 我的 .env 文件中有 APP_DEBUG=true 用于详细堆栈跟踪,但没有显示任何内容

  4. laravel.log 中没有显示错误

  5. 如果我将 URL 指向 img 文件夹内的徽标文件,浏览器将提供网站的徽标

  6. 我根据this answer设置文件夹权限

  7. /project = Laravel's 根文件夹

  8. /project/public = nginx 网络根目录

我的项目文件夹权限设置如下:

sudo chown -R www-data:www-data /project

sudo usermod -a -G www-data ubuntu

sudo chown -R ubuntu:www-data /project

sudo find /project -type f -exec chmod 664 {} \;    
sudo find /project -type d -exec chmod 775 {} \;

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

我的nginx 配置是:

server {

    server_name project.com.au www.project.com.au;
    root /home/ubuntu/project/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    access_log  /var/log/nginx/sc.access.log;
    error_log  /var/log/nginx/sc.error.log error;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/project.com.au/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/project.com.au/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {

    if ($host = www.project.com.au) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = project.com.au) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name project.com.au www.project.com.au;
    return 404; # managed by Certbot

}

第二个server 部分由letsencrypt / Cert-Bot 添加。

我的public文件夹的文件列表是:

-rw-r--r--+ 1 ubuntu www-data   281 Aug 16 16:02 browserconfig.xml
drwxr-xr-x+ 2 ubuntu www-data  4096 Aug 16 10:46 css
-rw-r--r--+ 1 ubuntu www-data  1150 Aug 16 16:02 favicon.ico
drwxr-xr-x+ 2 ubuntu www-data  4096 Aug 16 16:02 fonts
drwxr-xr-x+ 3 ubuntu www-data  4096 Aug 16 16:02 img
-rw-r--r--  1 ubuntu www-data  1823 Aug 16 16:36 index.php
drwxr-xr-x+ 2 ubuntu www-data  4096 Aug 16 10:46 js
-rw-r--r--+ 1 ubuntu www-data   720 Aug 16 16:02 manifest.json
-rw-r--r--  1 ubuntu www-data   192 Aug 16 16:02 mix-manifest.json
-rw-r--r--  1 ubuntu www-data    24 Aug 16 15:28 robots.txt
-rw-r--r--  1 ubuntu www-data   914 Aug 16 15:28 web.config

我的nginx 访问和错误日​​志没有任何条目/

我的项目错误日志为空。我的项目访问日志显示:

27.99.0.231 - - [19/Aug/2018:13:33:05 +0000] "GET / HTTP/1.1" 200 31 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"

我的主页是空白的,没有nginx 错误或laravel 堆栈跟踪。如果我将/img/logo.png 添加到基本 URL,则徽标会显示在页面中。

我还能去哪里看?所有研究都指向上面的 conf 文件,但我没有发现任何异常。

【问题讨论】:

    标签: php laravel nginx


    【解决方案1】:

    您必须配置索引页面在公用文件夹中,但我没有看到它完成。就我而言,我的 nginx .conf 如下所示:

    ...
    
    server {
    
    listen 80;
    listen 443 ssl;
    listen [::]:80;
    
    server_name domain.tld;
    root /var/www/public;
    index index.php index.html index.htm;
    
    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }
    
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }
    
    location ~ /\.ht {
        deny all;
    }
    
    error_log /var/log/nginx/laravel_error.log;
    access_log /var/log/nginx/laravel_access.log;
    ...
    

    我认为root行会解决你的问题

    【讨论】:

    • 嗨@Alejandro Garcia,muchissimas gracias! Usando tu config lo arregle!
    猜你喜欢
    • 2020-09-12
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    相关资源
    最近更新 更多