5 Proven ways to optimize Nginx for WordPress

5 Proven ways to optimize Nginx for WordPress

Table of Contents

ired of slow, inefficient WordPress websites?

Slow sites can even affect your business. Additionally, it creates load on the server and browsing becomes frustrating.

Luckily, with web servers like Nginx, there are ways to optimize WordPress websites.

At 1onlyhost, we often get requests from server owners to speed up their websites as part of our Server Administration services.

Today, we’ll see how our Support Engineers optimize Nginx for WordPress to make it load faster.


How we optimize Nginx for WordPress?

WordPress websites load quickly when we use a powerful server. Similarly, optimizing the WordPress templates, enabling faster DNS, content delivery network, etc. also helps.

Although, there are many ways to make WordPress faster, here we’ll be focusing on how to optimize Nginx for best WordPress performance.

Before we begin the optimization, we need to have an idea of the current state of WordPress website. That’s why, our Support Engineers primarily do a speed test of the website.

Working based on the current values will be more efficient than doing some blind tweaks.

Now, lets take a look at the top tweaks that our Dedicated Engineers make in Nginx configuration.


1. Enabling Keepalive

Web servers use a mechanism called keepalive connections to keep the connection open between the browser and the server even after completing a page request. For further page visits, it can use the idle keepalive connection rather than creating a new connection. As a result, it helps to reduce the usage of server resources.

Additionally, serving multiple files using the same connection can reduce latency and allow WordPress pages to load faster.

As a primary step towards Nginx optimization, our Support Engineers always ensure that Keepalive is turned ON on the server.


2. Set Browser caching headers

Secondly, we enable Browser caching headers in Nginx. Let’s now see how this helps in improving website speed.

In simple words, cache is a place that stores active data and makes it easier to access. So, if static files are stored in the cache, it helps in faster loading of WordPress. By setting up caching headers, we inform browsers to cache the pages.

From our experience in managing Nginx servers, we see that this would add more time to load the pages initially. But, if you have recurring visitors on your WordPress website, this will drastically reduce the site loading time. That’s why, our Dedicated Engineers recommend this to customers with repeated website visitors.


3. Gzip content

Compressing data reduces file size and make them easier to transfer. Again, this strategy can be used in WordPress speed optimization too.

Compression can be enabled using WordPress plugins WP Super CacheW3 Total Cache, etc. But, often these plugins come with a lot of data overhead and can increase the risk of conflicts. Thus, in all possible scenarios, we recommend customers to set up compression directly in the web server configuration.

Luckily, Nginx by default comes with compression methods like Gzip. But, the default setting will only compress certain file types like text/html.

To optimize Nginx for WordPress, our Dedicated Engineers also compress other files like java-script and CSS. For this, we use this setting in nginx.conf file.

gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;

Again, if the website is on shared hosting, we enable gzip compression in the website’s Nginx config file.


4. Install and tweak PHP FPM

Similarly, enabling PHP-FPM (PHP FastCgi Process Manager) can really help to speed up WordPress applications.

In this method, we set up an Nginx server to serve the static files. Additionally, when a user requests a PHP page, the Nginx server will forward the request to PHP itself. Further processing happens at PHP-FPM, which runs its own server.

In short, we isolate the PHP page processing to PHP-FPM, which again help to make website faster.

During this setup, our Server Administrators configure PHP with options like  --enable-fpm and --with-fpm . Further, we optimize the values at the file /opt/phpxx/etc/php-fpm.conf

Again, this involves further tweaking in each website’s virtual-host configuration too.

To improve the performance, we cache responses from FastCGI PHP applications.

When using FastCGI, we make use of the fastcgi_cache_key, fastcgi_cache_path, and fastcgi_cache_purge variables in the location block of each domain. Luckily, there are plugins available to configure this caching. This helps to purge the cache automatically after modifying or publishing a post.


5. Add Security Precautions

Likewise, it’s really worth to configure Nginx to avoid unauthorized access to your WordPress files. This can prevent attacks to your website.

To add to the security of WordPress website, our Dedicated Engineers use the location directive in Nginx config file. We tweak it to avoid users from executing scripts from the uploads directory, restrict WordPress Dashboard access to trusted IP addresses, deny access to wp-config.php, rate limit WordPress website logins and so on.

[Tired of slow loading WordPress website? Our Nginx Experts can make it load faster!]



In short, Nginx is a lightweight web server that really works with WordPress websites. Today, we saw how our Support Engineers optimize Nginx for WordPress websites by enabling caching, compression, php-fpm and more.

Leave a Comment

Your email address will not be published. Required fields are marked *

Social Share


Cheapest Web Hosting

Fasters Web Hosting Promo
Scroll to Top

Launch your Website at RS599

Create a professional website yourself with our domain hosting combo. Get Extra benefits at this Year end Sale with 10% OFF and Enjoy Amazing Deels on Shared Hosting!

Starting at Only RS599/Year

Year End Sale


Use Code STARTBIZ at Checkout.

Create an earning opportunity with A Web Hosting Business

Become reseller and start reselling domains, web hosting, ssl certificates and More.

45% OFF

Starting at RS399/Month


Use coupon: at the checkout.