Skip to content

Instantly share code, notes, and snippets.

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 funyx/21f87dbda9a4c56ac6cecf5fee5e78e8 to your computer and use it in GitHub Desktop.
Save funyx/21f87dbda9a4c56ac6cecf5fee5e78e8 to your computer and use it in GitHub Desktop.
Nginx: Codeigniter virtual host
server {
listen [port];
server_name [web url];
access_log [access_log_location];
error_log [error_log_location];
root [where_to_serve from];
index index.html index.php;
# If file is an asset, set expires and break
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
break;
}
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# Serve the directory/file if it exists, else pass to CodeIgniter front controller
location / {
try_files $uri $uri/ @codeigniter;
}
# CodeIgniter Front Controller
location @codeigniter {
internal;
root [where_to_serve_from];
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass php5-fpm-sock;
fastcgi_index index.php;
include fastcgi_config;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
location ~* \.php$ {
fastcgi_pass php5-fpm-sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
include fastcgi_config;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment