
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
Generate Fake Data In PHP With Faker
Relationship Table Data With Route Model Binding In Laravel
Plain PHP Resumable Large File Uploads In Chunks Using FlowJs
Accessors And Mutators In PHP Laravel
Multiple GIT Key Pairs Or Account In The Same Computer
Create A Composer Package? Test It Locally And Add To Packagist Repository
Laravel 7.x Multiple Database Connections, Migrations, Relationships & Querying
Run Raw Queries Securely In Laravel
Securely SSH Your Server & Push Files With FileZilla
Lazy Load Images In Chrome With This Simple Trick
Google, Twitter, GitHub, Facebook & Many Other Social Generic Logins With PHP Laravel Socialite