zhu2688
6/26/2012 - 3:33 PM

Zend with nginx

Zend with nginx

## Force redirect to www address
server {
  server_name  zf.local;
  rewrite ^(.+?)/?$ http://www.zf.local$1 permanent;
}

server {
  listen 80;
  server_name www.zf.local;
  index index.php;
  charset utf-8;
  keepalive_requests 100;

  root  /home/cf/workspace/zf/public;
  access_log  /var/log/nginx/zf/access.log;
  error_log  /var/log/nginx/zf/error.log;

  # remove trailing slash, that throws ZF router
  rewrite ^/(.*)/$ /$1 permanent;

  location ~ /\.ht {
    deny  all;
  }

  location = /favicon.ico {
    return 204;
    access_log     off;
    log_not_found  off;
  }

  ## Expires headers on known filetypes
  location ~* \.(ico|css|js|gif|jpg|jpeg|png|swf|pdf|html)$ {
    access_log off;
    log_not_found off;
    expires 10s; #1h, 10m, 1d, 1w, max
    break;
  }

  ## Enable robots.txt
  location = /robots.txt {
    rewrite (.*) /robots/robots.txt;
    break;
  }

  ## Enable sitemap.xml
  location = /sitemap.xml {
    rewrite (.*) /downloads/sitemap.xml;
    break;
  }

  if ($request_method !~ ^(GET|HEAD|POST)$ ) {
    return 444;
  }

  if ($http_user_agent ~* LWP::Simple|BBBike|wget|msnbot|scrapbot|Baiduspider|Jullo) {
    return 403;
  }

  location / {
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
    include /etc/nginx/fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_ignore_client_abort on;
  }
}