Skip to content

Instantly share code, notes, and snippets.

@Linnk
Created September 2, 2015 18:44
Show Gist options
  • Save Linnk/e7655b14a5b7d0244d12 to your computer and use it in GitHub Desktop.
Save Linnk/e7655b14a5b7d0244d12 to your computer and use it in GitHub Desktop.
NGINX configuration file for CakePHP projects with subdirectory
# NGINX Configuration for CakePHP projects with url subdirectories.
#
# In a classic-default-generic CakePHP project you can have as many
# independent applications as you want just by copying the app/
# directory. Apache and the .htaccess files will make the magic, but
# in a nginx server you will need a touch to your virtualhost conf.
#
# So, in order to make this:
#
# example.com/ —> ~/cakephp.dev/app/webroot/index.php
# example.com/friendly-url/* —> ~/cakephp.dev/app/webroot/index.php
# example.com/api/ —> ~/cakephp.dev/api/webroot/
# example.com/api/friendly-url/* —> ~/cakephp.dev/api/webroot/
#
# You will need the next configuration:
#
# Note: The order of the first location directive is important.
server {
listen 80;
server_name cakephp.dev;
index index.php;
location ~ ^/api(.*) {
root /Users/linnk/Code/cakephp.dev/api/webroot/;
rewrite ^/api/(.*)$ /$1 break;
try_files $uri /api/webroot/index.php$args;
location ~ \.php$ {
rewrite ^/api/(.*)$ /$1 break;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
}
root /Users/linnk/Code/cakephp.dev/app/webroot/;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment