If you’ve ever wondering how to config Laravel PHP web on nginx server, this post will show you how to do it.

Let say your site config named web-laravel.conf, create one under sites-available directory.

$ sudo vi /etc/nginx/sites-available/web-laravel.conf

The config will look like following:

server {
    listen 80;
    server_name web.laravel; // setup your domain name here
    root /var/www/web-laravel/public;

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

    location ~ /\.ht {
        deny all;

At root option, you should point to public directory inside the Laravel project. Okay, so it’s ready to serve Laravel websites from now. Just make sure to verify nginx config again to avoid any mistake and restart nginx server.

$ sudo nginx -t

$ sudo systemctl restart nginx.service