TheRealPapa
TheRealPapa

Reputation: 4539

Serving empty blank page without errors

First time doing this. Two days since I struck this issue and have not located the problem.

I installed laravel on a Ubuntu 18.04 instance on EC2. The project works fine in my local Homestead environment. After a battle with permissions I am now stuck with blank pages served by nginx/laravel.

I am looking to set up permissions so that user ubuntu can deploy updates from BitBucket, while www-data can run the Laravel application.

I am stuck as I cannot seem to find where an error is logged / occurring.

A few points;

  1. No errors in the site's nginx error log

  2. Nginx shows HTTP 200 response code in the site's access log

  3. I have APP_DEBUG=true in my .env file for verbose stack traces, but nothing shows

  4. I have no errors showing in the laravel.log

  5. Browser will serve the site's logo if I point the URL to the logo file inside img folder

  6. I set folder permissions based on this answer

  7. /project = Laravel's root folder

  8. /project/public = nginx web root

My project folders permissions have been set like this:

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

My nginx config is:

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

}

The second server section was added by letsencrypt / Cert-Bot.

A file list of my public folder is:

-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

My nginx access and error logs do not have any entries/

My project error log is empty. My project access log shows:

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"

My home page is served blank, no nginx errors, or laravel stack traces. If I add /img/logo.png to the base URL, then the logo is shown in the page.

Where else could I look? All research points to the conf file above bu I have not found anything out of the ordinary with mine.

Upvotes: 2

Views: 5022

Answers (1)

Alejandro García
Alejandro García

Reputation: 168

You have to configure that the index page is inside public folder, and I don't see it done. In my case, my nginx .conf looks like this:

...

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

I think the line of root will solve your problem

Upvotes: 2

Related Questions