Created
September 2, 2015 18:44
-
-
Save Linnk/e7655b14a5b7d0244d12 to your computer and use it in GitHub Desktop.
NGINX configuration file for CakePHP projects with subdirectory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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