Optimzing nginx for Ghost and PHP

Running Ghost on the same server as a PHP application isn’t as difficult as it once was.


  • server_tokens off;
    Ensures that your server isn’t displaying the version
  • gzip on;
    In addition to these settings:
    gzipvary on;
    proxied any;
    gzip_comp_level 9;
    gzipbuffers 16 8k;
    gzip_http_version 1.1;
    types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

As much as I wanted, compiling ngx_pagespeed didn’t seem like the right thing to do at this time. Haven’t had much experience with gzip, but thought turning up compression to the max was the best thing to do for now.

My one PHP app is currently an invision power board site. Initially it had problems with it’s seo settings, and saw that many IPB users were expressing desire to solve the Friendly-URL problems on nginx. Eventually, I found an excellent reference on the Xenforo help documentation on this topic – and used two of the suggestions:

The first goes in the root location block:
try_files $uri $uri/ /index.php?q=$request_uri;

The second added some links to the php files block for fastcgi:
location ~ \.php$ {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

Google’s Pagespeed site said that I wasn’t using browser caching, so added this:
location ~*\.(?:ico|css|js|gif|jpe?g|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate"; }

Ghost needed a restart to work properly, but the development IPB forum is doing quite well.

The IBP FURLs are now at the same settings as they were when on the Apache server, with no added .htaccess file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.