ScaleScaleScaleScale

Tips / Nginx


Nginx configuration for WordPress

Wordpress + Nginx

WordPress rewrite rules for Nginx

WordPress is one of the most popular CMS of all times, it’s flexible, easy and have lot of plugins to use. However, sometimes wordpress get’s slower and becomes a resource hog at RAM and CPU level. One of the solutions to fix this is to active plugins like W3 T’otal Cache and so on. However, sometimes that is not enough and you may start thinking about other solutions, like moving to a lightweight webserver platform, like Nginx.

Nginx configuration for WordPress is extremely easy. This an example of the same block we use on NginxTips. Inside the server block, you should define a location block, like this:

location / {

root /var/www/sites/nginxtips.com;
index index.php index.html index.htm;

# WordPress permalinks
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
break;
}

}

That’s all you need to replace the old .htaccess used in WordPress while you used Apache.

Give it a try and let us know about your results đŸ˜€

Popular search terms:

  • Nginx for wordpress
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • With wordpress multisite? WordPress rewrite rules?

  • Dmitry Averin

    Hello, Esteban! Thank you very much for your site! I am your subscriber.
    Asking for Your help: I renamed the WordPress folder in XXX before installation. Help me please to set up permalinks. Now I get a 404 when trying to go to a page with a Permalink.

  • I found the solution-
    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    # Add trailing slash to */wp-admin requests.
    rewrite /XXX/wp-admin$ $scheme://$host$uri/ permanent;

    location ~* .(jpg|jpeg|png|gif|css|js|ico)$ {
    expires max;
    log_not_found off;
    }

    • nginxadmin

      Glad you found the solution Dmitry! Thanks for sharing.