Best nginx rewrite setting for Wordpress

Nginx promises a lot feature of web server. From nginx website nginx accelerates content and application delivery, improves security, facilitates availability and scalability for the busiest web sites on the Internet. From our last post nginx web server has unique system to do that.

Rich feature has weakness too. Speed for static code and recommended for static content should be tweak to combine that plus. One of them is rewrite module to handle dynamic content.

Some article recommend to tweak your nginx setting to add rewrite module. In my virtual private server this setting can be found in /usr/local/apps/nginx/etc/conf.d/common. you can edit with nano tool or something else. Some setting add

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

That setting true but in some case is not perfect. my website https://www.langsungenak.com implemented this code but found error with search with relevansi plugin. First page of search looks good but see in page 2 and more. My website show last article in search.

Write another ones must be implemented. i write simple code like our post in this website with if case. First don`t forget edit config with

nano /usr/local/apps/nginx/etc/conf.d/common

add with if case like this

if (!-e $request_filename)
{
  rewrite ^(.+)$ /index.php?q=$1 last;
}

dont forget to do web server restart with

service nginx restart

adding new configuration must be restart before nginx executed them. This is another differences nginx and apache web server. see another article about error in nginx restart in this

0/5 (0 Reviews)

LEAVE A REPLY

Please enter your comment!
Please enter your name here