Report this

What is the reason for this report?

How do you get Nginx to server a Laravel page?

Posted on October 31, 2017

I made a one_click ubuntu LEMP drop, installed composer, installed larval, created a new larval installation, edited /etc/nginx/sites-available/default server section with:

        root /home/myUserName/myAppName/public;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name myIpAddress;

restarted nginx No errors in any of the above. Point my browser to the ip and I still see the DigitalOcean welcome screen rather than Laravel’s. What am I missing?

I’ve read and followed (I think) all the tutorials I can find – any help is greatly appreciated.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Your Nginx server block for a Laravel application should look as follows:

server {
    listen 80;
    server_name server_domain_or_IP;
    root /var/www/travellist/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;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

You can follow this step by step tutorial on how to install Laravel with LEMP here:

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-laravel-with-nginx-on-ubuntu-22-04

Alternatively, you can use this 1-Click installation image here:

https://marketplace.digitalocean.com/apps/laravel

Here is a step by step tutorial on how to use the 1-Click installation image:

How to Install Laravel on DigitalOcean with 1-Click?

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.