Change nginx configuration file for deploying Laravel and Vue.js project on a Linux server

Posted by

Change nginx conf file

Change nginx conf file (Deploy Laravel and Vue js Project with Linux Server)

In order to deploy a Laravel and Vue.js project on a Linux server using Nginx, you will need to change the Nginx configuration file to properly serve your application. Follow the steps below to make the necessary changes to the Nginx conf file.

Step 1: Access the Nginx conf file

  
    SSH into your Linux server and navigate to the Nginx configuration directory. You can usually find the Nginx conf file in the /etc/nginx/ directory.
  

Step 2: Edit the Nginx conf file

  
    Open the Nginx conf file using a text editor such as nano or vim. Once inside the conf file, locate the server block that corresponds to your domain or IP address.
  

Step 3: Configure the server block

  
    Inside the server block, you will need to add a few configuration directives to properly serve your Laravel and Vue.js project. Below is an example configuration that you can use as a starting point:

    server {
        listen 80;
        server_name your_domain.com;

        root /path/to/your/project/public;
        index index.php index.html index.htm;

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

        location ~ .php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

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

        location /public {
          root /path/to/your/project/public;
        }

        location /storage {
          alias /path/to/your/project/storage/app/public;
        }
    }
  

Step 4: Restart Nginx

  
    Once you have made the necessary changes to the Nginx conf file, save the file and exit the text editor. Then, restart Nginx to apply the changes with the following command:

    sudo service nginx restart
  

That’s it! You have now successfully changed the Nginx conf file to deploy your Laravel and Vue.js project on a Linux server. Your application should now be up and running and accessible through your domain or IP address.