Fix WordPress 404 error on NGINX server

Everybody know, Apache server is most popular server type because its simple and it was supported by a very motivate community. But, there is another web server type that has better efficiency and quite stable - NGINX. If you haven't used this type before, you should give it a try and you will be amazed. If we run a WordPress site on NGINX, sometimes we can't get rid of 404 error when we have selected Custom permalink option. Here is the method to fix WordPress 404 error on NGINX server.

Fix WordPress 404 error on NGINX server fix wordpress 404 error on nginx server Fix Wordpress 404 error on NGINX server concentrated man in glasses drawing blueprints 1024x683

Profile of concentrated bearded man in glasses sitting and drawing blueprints on computer

There is an issue in NGINX, it doesn't use mod_rewrite like Apache, it has its own command to config url rewrite on webpage. That means, on NGINX server you can't do anything on WordPress that relates with .htaccess file. So, how do we handle rewrite method to make it works on NGINX?

Of course, we will use NGINX commands to rewrite uri by insert NGINX configuration file of the running website and make it works like we works on .htaccess file in Apache. Move on, open the domain configuration file on NGINX and find this string: "location / {.....} "  then replace it with these lines:

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

Okay, now just type service nginx restart command to restart NGINX server and let it takes effect.
Hope this trick could be helpful for anyone who prefer NGINX than Apache for WordPress. IF you have any experience or better idea, please let me know or just comment below.

=== Fix WordPress 404 error on NGINX server === Fix WordPress 404 error on NGINX server === Fix WordPress 404 error on NGINX server ===