Skip to content

Instantly share code, notes, and snippets.

@abpin
Created September 21, 2012 02:00
Show Gist options
  • Save abpin/3759378 to your computer and use it in GitHub Desktop.
Save abpin/3759378 to your computer and use it in GitHub Desktop.
nginx.conf File For ExpressionEngine or Codeigniter
server {
listen :80;
server_name www.example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
server {
server_name example.com;
listen :80;
root /srv/www/example.com/public;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
index index.html index.php;
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^ /index.php last;
}
if ($request_uri ~* ^(/site(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ \.php {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment