Skip to content

Instantly share code, notes, and snippets.

@lynxluna
Created June 28, 2011 10:16
Show Gist options
  • Save lynxluna/1050850 to your computer and use it in GitHub Desktop.
Save lynxluna/1050850 to your computer and use it in GitHub Desktop.
NginX configuration for CodeIgniter Apps with PATH_INFO and subdomain
server
{
# GENERAL CONFIGS
listen 8000;
server_name example.com .example.com;
root /var/example/current/site;
index index.html index.htm index.php;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# NO WWW!
if ($host ~* ^www\.([a-z0-9]*)\.(example\.com) )
{
set $storename $1;
set $host_without_www $2;
rewrite ^/(.*)$ $scheme://$storename.$host_without_www/ permanent;
}
# WWW1 WWW32342424324 reserved for future use
if ($host ~* ^www([0-9]*)\.(example\.com))
{
set $host_without_www $2;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# cdn1 cdn2 cdn3 reserved for future use
if ($host ~* ^cdn([0-9]*)\.(example\.com))
{
set $host_without_www $2;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
if ($host ~* ^([a-z0-9]+)\.(example\.com))
{
set $storename $1;
set $host_without_www $2;
rewrite ^/$ /index.php/storepage/show/ last;
rewrite ^/(.+)$ /index.php/$1 last;
}
# ROOT Location
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location = /favicon.ico {
access_log off;
log_not_found off;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
# PHP Configs
fastcgi_intercept_errors on;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
}
}
@lynxluna
Copy link
Author

The line #47

rewrite ^/$ /index.php/storepage/show/ last;

it's used if you are processing subdomain name for a controller. eg. if you are using http://somestore.example.com/ and you want to process subdomain name (ie somestore) on storepage controller using the show method, then you put your controller url on it.

@tim-peterson
Copy link

Thanks for this gist. Unfortunately I tried doing what you said without luck so far. I turned this into a question on Stackoverflow so others could benefit http://stackoverflow.com/questions/15262031/subdomain-nginx-codeigniter

Would you mind taking a look there to see what you think?

thanks,
tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment