Nginx .htaccess alternative for WordPress


After migration from apache to nginx, your website can’t run. You will get the error:

 404 Not Found

nginx

Because Nginx doesn’t support .htaccess file. You can follow these steps below:

Step 1: Find your domain conf file i.e. /usr/local/nginx/conf/conf.d/tutorialspots.com.conf

nginx domain conf file location

Step 2: use code:

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

I.e.

# Centmin Mod Getting Started Guide
# must read http://centminmod.com/getstarted.html

# redirect from non-www to www 
# uncomment, save file and restart Nginx to enable
# if unsure use return 302 before using return 301
#server {
#            listen   80;
#            server_name tutorialspots.com;
#            return 301 $scheme://www.tutorialspots.com$request_uri;
#       }

server {
  server_name tutorialspots.com www.tutorialspots.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/tutorialspots.com/log/access.log combined buffer=256k flush=60m;
  error_log /home/nginx/domains/tutorialspots.com/log/error.log;

  root /home/nginx/domains/tutorialspots.com/public;

  location / {

# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  # More example Nginx vhost configurations at
  # http://centminmod.com/nginx_configure.html
  #try_files    $uri $uri/ /index.php;
	try_files $uri /index.php$is_args$args;
	
  }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
  include /usr/local/nginx/conf/vts_server.conf;
}

Step 3: restart nginx

service nginx restart

Done!

Related Post

, , ,

No comments yet.

Leave a Reply