Tag: nginx

NGINX TLS Time To First Byte

Ilya Grigorik on optimizing NGINX TLS time to first byte (TTTFB):

let’s now turn to the practical matter of picking and tuning the server to deliver the best results. One would hope that the default “out of the box” experience for most servers would do a good job… unfortunately, that is not the case. Let’s take a closer look nginx

In the simplest terms, TLS involves more work. The current realities of securing communications means we don’t have a good way to avoid doing that additional work, indeed we will be doing it more often than we ever have before. The end result is that we need to spend more time thinking about how to optimize the HTTPS experience for all users.


MNPP is Mac + Nginx + Percona + PHP. Could be a handy alternative to MAMP.

Nginx, Redirect non-SSL Requests

Since I managed to do this incorrectly a couple of times I figured it was worth noting here.

You already have a working site setup in Nginx that uses SSL. Now you want to make sure that any non-SSL requests to the site get redirected. Turns out to be very simple:

server {
  listen 80;
  server_name example.com;
  rewrite ^(.*) https://$server_name$1 permanent;

This sends back an HTTP/1.1 301 Moved Permanently response for non-SSL requests for example.com.

Three short and easy to read lines, I like it.

WordPress Pretty Permalinks with Nginx

Setting Permalinks in WordPress is simple and flexible. Core WordPress checks to see if the Apache mod_rewrite module is loaded before fully enabling permalinks. If that check fails then it includes index.php in your permalink structure in order to make sure that WordPress still gets a chance to process URLs.

Servers using Nginx are able to do URL rewriting, but the check still fails, leaving index.php in the permalink. Fortunately a few lines of PHP in a plugin (I like to put it in wp-content/mu-plugins/nginx.php) can fix that:

add_filter( 'got_rewrite', 'nginx_has_rewrite', 999 );
function nginx_has_rewrite( $got_rewrite ) {
    return TRUE;

Those few lines of PHP will tell WordPress that full URL rewriting is available on the server, so no more index.php in the permalink structure.

Before adding this make sure that you’ve already setup URL rewriting in your Nginx configuration.

Update: In the comments Sivel mentioned another alternative:

add_filter( 'got_rewrite', '__return_true', 999 );

The __return_true function was added during WP 3.0 development for exactly these sorts of things, where you want to just return TRUE for a filter. I like it.

Links for Tue 12 Feb 2008

© 2014 Joseph Scott

Theme by Anders NorenUp ↑