Now we need to give the web server user write access to the storage and cache folders, where Laravel stores application-generated files:
sudo chown -R www-data.www-data /var/www/your_domain/storage
sudo chown -R www-data.www-data /var/www/your_domain/bootstrap/cache
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
create a new virtual host configuration file at
/etc/nginx/sites-available
:
sudo nano /etc/nginx/sites-available/your_domain
The following configuration file contains the recommended settings for Laravel applications on Nginx:
server {
listen 80;
server_name server_domain_or_IP;
root /var/www/your_domain/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/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Copy this content to your /etc/nginx/sites-available/travellist file and, if necessary, adjust the highlighted values to align with your own configuration. Save and close the file when you’re done editing.
To activate the new virtual host configuration file, create a symbolic link to travellist in sites-enabled:
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
To confirm that the configuration doesn’t contain any syntax errors, you can use:
sudo nginx -t
You should see output like this:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
To apply the changes, reload Nginx with:
sudo systemctl reload nginx
Now go to your browser and access the application using the server’s domain name or IP address, as defined by the server_name directive in your configuration file:
http://server_domain_or_IP