TYPO free

home

fighting for TYPO free code

TYPO3 Nginx configuration v2

14 Jul 2011

It's been a while since I posted my Nginx configuration for TYPO3. It's been updated recently. I run several sites that use similar configuration options, so I split off parts of the configuration into include files.

The main configuration for somesite.org:

server {
  listen 109.74.192.51;
  server_name somesite.org;
  rewrite ^ $scheme://www.somesite.org$request_uri? permanent;
}
server {
  listen 109.74.192.51;
  server_name www.somesite.org;
  set $basename 'somesite.org';
  root /var/www/$basename;

  include include/expires-typo3.conf;
  include include/staticfile-typo3.conf;
  include include/php-fastcgi.conf;
}


The expires conf:

location = /favicon.ico {
  expires max;
}
location = /clear.gif {
  empty_gif;
  expires max;
}
location ^~ /typo3/gfx {
  expires max;
}
location ^~ /typo3temp/compressor {
  expires max;
}
location ~* \.(cur|ico|gif|png|jpe?g|css|js|swf|woff)((\?\d\d\d\d\d\d\d\d\d\d)|(\?s=\d\d\d\d\d\d\d\d\d\d))$ {
  expires max;
}
location ~* ^(/typo3/sysext|/typo3conf/ext).*\.(cur|ico|gif|png|jpe?g|css|js|swf|woff) {
  expires max;
}
location ~* \.(sql|htaccess|htpasswd) {
  deny all;
}
location ~* \.(cur|ico|gif|png|jpe?g|css|js|swf|woff)(\?v\d\d?\.\d\d?\.\d\d?)$ {
  expires max;
}

 

The staticfile-typo3.conf:

set $static 1;
 
if ($http_pragma = 'no-cache') {
  set $static 0;
}
 
if ($http_cache_control = 'no-cache') {
  set $static 0;
}

if ($http_cookie = 'nc_staticfilecache|be_typo_user') {
  set $static 0;
}
 
if ($request_method = 'POST') {
  set $static 0;
}

if ($query_string) {
  set $static 0;
}

if (!-f $document_root/typo3temp/tx_ncstaticfilecache/www.$basename${request_uri}index.html ) {
  set $static 0;
}

if ($static = 1) {
  rewrite .* /typo3temp/tx_ncstaticfilecache/www.$basename${request_uri}index.html last;
}

location ^~ /typo3temp/tx_ncstaticfilecache {
  expires 43200;
  charset utf-8;
}

 

The php-fastcgi.conf:

try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
  try_files     $uri =404;
  fastcgi_pass  unix:/var/run/php-fcgid/.fastcgi.www-data/socket;
  fastcgi_index index.php;
  include       fastcgi_params;
}

 

So, there you have it. Please post comments an suggestions.

 

 

Prune 14 Jul 2011, 22:47
Hi,

I'm doing bench of typo3 using apache+php, nginx+php-fpm, varnish and soon apache+php-fpm and apache+fastcgi-php

Can you please provide any tuning you did on Nginx or the Fastcgi config ?

For example, in /etc/php-fpm.d/www.conf I set :
pm.max_children = 30
(I also tested with pm.max_children = 5) to limit the load on the backend host.
For the moment, I can handle 50 parallel users with a 5 second lattency... better slow than dead host isn't it ?
I can provide graphs results when all tests are done...
Michiel 14 Jul 2011, 23:54
Hi Prune,

I use php-fcgi as it comes with debian. fpm does not. I use as many children as the available memory will allow. Currently about 15.

I did a little tuning on the cgi:

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffers 256 4k;

Otherwise nginx is configured pretty much default, running 6 workers.
ShareUrThoughts 11 Aug 2011, 08:00
I gonna try code, I hope it will help!
Rove 6 Jan 2012, 18:20
Hi,

I just found a small bug on line 17 of the expires conf, it is missing a dollar sign at the end to match the file extension, not something in the file name.

For example, the PHPMyAdmin extension for TYPO3 have a file named "phpmyadmin.css.php" - that gets matched as a css file rather a php file, and the server returns the php source code, rather rendering the php file.

So line 17 should be,

location ~* ^(/typo3/sysext|/typo3conf/ext).*\.(cur|ico|gif|png|jpe?g|css|js|swf|woff)$ {
Shamier 14 May 2012, 09:40
Thnx for the post!
Commenting is closed for this item