Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ushiro's avatar

Nginx server block for Laravel not working

Hi, I have been using Apache virtual hosts to serve my Laravel projects locally in Ubuntu 20.04 and am a complete novice in Nginx, but now I need to set up a server block for a Laravel-Next.js project where the Next.js is located in a /client directory in the laravel app. I am initially trying to just get the laravel project to open but have had no success thus far. My project directory is located in /var/www/test-project. This is the configuration file test-project.com in /etc/nginx/sites-available:

server {
    listen 80;

    server_name test-project.com www.test-project.com;

    root /var/www/test-project/public;

    index index.php index.html index.htm index.nginx-debian.html;

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


}

When I try to open in the browser test-project.com, it just redirects to hugedomains.com. I also have apache in my system, but have stopped the service beforehand and kept only nginx running. Any ideas would be much appreciated

0 likes
5 replies
Snapey's avatar

Did you point your DNS to the server IP?

ShahedPHP's avatar

Seems like your DNS is pointing elsewhere, I’d usually go on my domain provider and point it to Cloudflare. And from there point my domain to my server. This is for a live server right and not for local development?

sudo ln -s /etc/nginx/sites-available/{SITE_CONF} /etc/nginx/sites-enabled/

Replace {SITE_CONF} with your NGINX file name

As for your NGINX file

If your using PHP 8.1 it’s fine but if not replace 8.1 with the version you have installed.

fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

Reload the NGINX to update configuration and if theres an error when running post below but if there isn’t it should show on the browser.

sudo systemctl reload nginx
sudo nginx -t

Also run this if you haven’t (file/folder permissions)

sudo chown -R www-data.www-data /var/www/test-project/storage
sudo chown -R www-data.www-data /var/www/test-project/bootstrap/cache

I just realised this post is three years old lol.

Please or to participate in this conversation.