Question

How do you get Nginx to server a Laravel page?

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.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
July 24, 2023

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel