
Good content takes time and effort to come up with.
Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.
There are many times when you have installed NGINX but sometimes you will come across the weird thing ie 404 not found.
In thing article I will walk you through how to get it resolved.
You have NGINX installed. If not then in Ubuntu or any Debain version you can install with the following
sudo apt-get update
sudo apt-get install nginx
Most of the times developer change the configuration file and forget to restart the NGINX server
First TEST if the NGINX configuration is correct or not with the following command
sudo nginx -t
If everything is correct then run the reload
command
sudo service nginx reload
I have written a detailed article on how to install and manage your NGINX server in Linux don't forget to check it out How To Install NGINX In Linux / Ubuntu Package Manager & Manage It.
All your configuration files resides in /etc/nginx/sites-available
& once you activate them they will be in /etc/nginx/sites-enabled
which are eventually the symbolic link to sites-available
.
By default the default
configuration file will be enabled first go to sites-enabled folder and remove the soft link of default. Don't worry you can activate it later.
You might have your website configuration file in sites-available
For Eg. Mine is stackcoder.in which wont be activated inside sites-enabled
. To activate the configuration file use the following code
sudo ln -s /etc/nginx/sites-available/stackcoder.in /etc/nginx/sites-enabled/
Make sure to change it to your configuration file name.
Go to your website configuration file inside /etc/nginx/sites-available/stackcoder.in
, here mine is stackcoder.in your's might be different. And here you look for the following code block
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
Check if this path exists unix:/var/run/php/php7.2-fpm.sock
If your using LARAVEL project with NGINX configuration file then make sure to include the following file inside /etc/nginx/sites-available/stackcoder.in
make sure to check your configuration file name and make the following changes
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
NOTE: Don't forget to restart the NGINX server after doing this
Sometimes you might have set the wrong path for fastcgi_param
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
I prefer the following one
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
OR
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
Yup you read it right. Some times you will face problems when you might have installed the project in wrong directory, or directory without proper permission privileges issues.
Cross check if the project path and any other path given in NGINX configuration is correct or not.
Check if there are any permission issues. You can find the error logs in /var/log/nginx/error.log
Some times NGINX can be mischievous, He he he! kidding. Just re-installing works
To remove
NGINX use the following command
sudo apt-get remove nginx
To install
it again use the following command
sudo apt-get install nginx
Hope this article helped you. I have written other articles on NGINX kindly check them too
How To Cache Static Files With NGINX Server
Redirect www to a non-www website or vice versa
How To Create Free SSL Certificate With Lets Encrypt/Certbot In Linux (Single / Multiple Domains)
How To Install Linux, NGINX, MYSQL, PHP (LEMP Stack) on Ubuntu
SummerNote WYSIWYG Text Editor
Detect AdBlocker With Javascript And Increase Website Ads Revenue
SQLite Doesn't Support Dropping Foreign Keys in Laravel
Client-Side DataTable, Adding Super Powers To HTML Table
Create Gmail App Password For SMTP Mails
Factory States For Clean And Fluent Laravel Testing
composer.json v/s composer.lock
Website Speed and Performance Optimizations
Free SSL Certificate With Lets Encrypt/Certbot In Linux (Single / Multiple Domains)
What Is Method Chaining In PHP?
Install Letsencrypt SSL Certificate for RabbitMQ Server and RabbitMQ Management Tool
Factories To Speed Up Test-Driven Development In Laravel