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

siyabdev's avatar

Nginx is unable to handle requests from custom domain

I follwed Mohamed Said's "Servers for Laravel" laracasts series. In a lesson, he shows how to set up a custom domain to point to our laravel on the VPS. I followed the same but unable to make it work. The desire result is that on hitting the IP address, it should open nginx default page (which is working fine) but on hitting the domain name, the actual laravel app (which doesn't work)

/etc/nginx/sites-available/mysite.com

server {
   listen 80;
   listen [::]:80;
   server_name www.siyab.dev;
   return 301 http://siyab.dev;
}

server {
    listen 80;
    listen [::]:80;
    server_name siyab.dev;
    root /home/laracasts/www/public;

    index index.html index.htm index.php;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
    }
}

/etc/nginx/sites-available/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    root /var/www/html;

    index index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

I have symlinked both, verified the nginx configuration and reload nginx. I am using DigitalOcean droplet and Namecheap for my domains. See the attached screenshots.

Alt text

Result: Alt text

0 likes
5 replies
LaryAI's avatar
Level 58

To resolve the issue where Nginx is unable to handle requests from your custom domain and serve your Laravel application, follow these steps:

  1. Verify DNS Settings: Ensure that your domain (siyab.dev) is correctly pointed to your server's IP address. You can use tools like dig or online services like whatsmydns.net to verify DNS propagation.

  2. Check Nginx Configuration: Ensure that your Nginx configuration files are correctly set up and symlinked. Based on your provided configuration, it looks mostly correct, but let's double-check a few things.

  3. Nginx Configuration Files:

    • /etc/nginx/sites-available/mysite.com:

      server {
          listen 80;
          listen [::]:80;
          server_name www.siyab.dev;
          return 301 http://siyab.dev;
      }
      
      server {
          listen 80;
          listen [::]:80;
          server_name siyab.dev;
          root /home/laracasts/www/public;
      
          index index.html index.htm index.php;
      
          location / {
              try_files $uri $uri/ /index.php?$query_string;
          }
      
          location ~ \.php$ {
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/run/php/php8.2-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
          }
      }
      
    • /etc/nginx/sites-available/default:

      server {
          listen 80 default_server;
          listen [::]:80 default_server;
          server_name _;
          root /var/www/html;
      
          index index.nginx-debian.html;
      
          location / {
              try_files $uri $uri/ =404;
          }
      }
      
  4. Symlink Configuration: Ensure that the configuration file is symlinked correctly in /etc/nginx/sites-enabled/:

    sudo ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/
    
  5. Test Nginx Configuration: Test the Nginx configuration for syntax errors:

    sudo nginx -t
    
  6. Reload Nginx: If the configuration test passes, reload Nginx to apply the changes:

    sudo systemctl reload nginx
    
  7. Check File Permissions: Ensure that the Nginx user (usually www-data) has the necessary permissions to read the Laravel application's files:

    sudo chown -R www-data:www-data /home/laracasts/www
    sudo chmod -R 755 /home/laracasts/www
    
  8. Verify PHP-FPM Socket: Ensure that the PHP-FPM socket path is correct and that PHP-FPM is running:

    sudo systemctl status php8.2-fpm
    
  9. Check Laravel Logs: If the domain still doesn't serve the Laravel application, check the Laravel logs for any errors:

    tail -f /home/laracasts/www/storage/logs/laravel.log
    

By following these steps, you should be able to diagnose and fix the issue with Nginx not serving your Laravel application from the custom domain. If you encounter any specific errors during these steps, please provide the error messages for further assistance.

JussiMannisto's avatar

You created an A record with the host siyab.dev on your domain siyab.dev. That translates to siyab.dev.siyab.dev.

Use @ in the host field to refer to the root domain.

siyabdev's avatar

@JussiMannisto, I changed it to @ but still it says the page "Refused to connect". https://whatsmydns.net shows that the domain points to the correct IP address but page doesn't load. I think something might be wrong on the server side i.e. nginx

JussiMannisto's avatar

@siyabdev One problem at a time. DNS records were wrong, so the site couldn't have worked earlier. Now they seems ok.

A couple of questions:

  • Have you restarted Nginx after making config changes?
  • Did you modify the default Nginx config or did you copy the config that you showed from somewhere?
  • Have you installed PHP and all the necessary extensions on the server? Is your PHP version 8.2 as the Nginx config shows? You can verify it by running php -v
  • Nginx usually runs under a user named www-data. Does that user have read and write access to /home/laracasts/www/ and all its subdirectories?

Whenever you have problems, the first thing to do is check the error logs. Nginx logs are usually located under /var/log/nginx/.

Btw, Laravel.com has a section dedicated to deploying on Nginx: https://laravel.com/docs/11.x/deployment#nginx

JussiMannisto's avatar

I just noticed your Nginx config is under /etc/nginx/sites-available/. Those site settings aren't loaded automatically. You need to have a symbolic link to that file in the /etc/nginx/sites-enabled/ directory. Do you have that?

In case you don't, go to /etc/nginx/sites-enabled/, run sudo ln -s ../sites-available/filename.conf filename.conf, and then restart Nginx.

Please or to participate in this conversation.