Skip to content

Instantly share code, notes, and snippets.

@tim-peterson
Created August 29, 2012 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-peterson/3517383 to your computer and use it in GitHub Desktop.
Save tim-peterson/3517383 to your computer and use it in GitHub Desktop.
full nginx.conf for mysite.com
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http{
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name mysite.info;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
server_name test.mysite.info;
rewrite ^ https://mysite.info/test/$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/mysite_com.crt;
#(or .pem)
ssl_certificate_key /etc/ssl/mysite.com.key;
server_name .mysite.info;
root /var/www;
# index index.html index.php index.htm;
# access_log /var/log/nginx/access.log;
# error_log /var/log/nginx/error.log;
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.php;
location = /50x.php {
root /var/www;
}
# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/mall(/index)?|/index(.php)?)/?$){
rewrite ^(.*)$ / permanent;
#rewrite ^/(.*) http://mysite.info/$1 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;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# catch all
error_page 404 /index.php;
location / {
#try_files $uri $uri/ /index.php;
index index.html index.php;
}
# catch all
#error_page 404 /index.php;
# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /\.ht{
deny all;
}
} #end server
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
} #end http
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment