How to fix SEO friendly URLs in NGINX for WordPress sites

It is very simple to configure your NGINX based SEO friendly URLs for WordPress sites
root@www1:/#
Now open the NGINX configuration directory by using below steps
root@www1:/# cd /etc/nginx/sites-enabled/ root@www1:/etc/nginx/sites-enabled#
Now open the default file using any text editor, I am using VI for this purpose
root@www1:/etc/nginx/sites-enabled# vi default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/ server_name localhost;
####Please add below lines for SEO Friendly URLs
location / {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
###Disable from here##
# location / {
# # First attempt to serve request as file, then
# # as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# # Uncomment to enable naxsi on this location
# # include /etc/nginx/naxsi.rules
# }
# # error_page 404 /404.html;
# # error_page 500 502 503 504 /50x.html;
# # location = /50x.html {
# # root /usr/share/nginx/html;
# # }
####Disable till here###
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Now Restart your nginx service
root@www1:/etc/nginx/sites-enabled# /etc/init.d/nginx restart * Restarting nginx nginx ...done. root@www1:/etc/nginx/sites-enabled#
After doing the above configuration goto your wordpress site:
http://yourwordpresssite.com/wp-admin

Comments are closed.