Last active
December 11, 2015 03:49
-
-
Save Phally/4541119 to your computer and use it in GitHub Desktop.
This gist describes briefly how to setup a virtual host for nginx that will be a project as a sub folder. Please note that you need a virtual host like this one for every project you have.
This file contains hidden or 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
<?php | |
// In APP/Config/bootstrap.php add the following code: | |
if (($baseUrl = Configure::read('App.baseUrl')) !== false) { | |
Configure::write('App.base', $baseUrl); | |
} |
This file contains hidden or 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
<?php | |
// In APP/Config/core.php uncomment the line: | |
Configure::write('App.baseUrl', env('SCRIPT_NAME')); |
This file contains hidden or 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
# Author: Frank de Graaf (Phally) | |
# Date: 15-01-2013 | |
# Location for the project. | |
location /myproject { | |
# Basic password protection. | |
auth_basic "Authorization required"; | |
auth_basic_user_file htpasswd/myproject; | |
# The webroot of the project. | |
root /home/phally/projects/myproject/webroot; | |
# Strip a trailing slash if any and redirect. | |
rewrite (.+)/$ $1 permanent; | |
# Strip the sub folder name. | |
rewrite ^/myproject/(.+)$ /$1 break; | |
# For all other php files which aren't for the CakePHP | |
# core. Example: CakePHP test suite. | |
location ~ \.php$ { | |
# Strip the sub folder name. | |
rewrite ^/myproject/(.+)$ /$1 break; | |
# Pass it to PHP-FPM. | |
fastcgi_pass 127.0.0.1:9000; | |
# Include the fastcgi parameter commands. | |
include /etc/nginx/fastcgi_params; | |
# Prepend the sub folder name to the script name. | |
fastcgi_param SCRIPT_NAME /myproject$uri; | |
} | |
# Try static files first, else pass it on to CakePHP. | |
try_files $uri @myproject; | |
} | |
# Location for the CakePHP paths. | |
location @myproject { | |
# Pass it to PHP-FPM. | |
fastcgi_pass 127.0.0.1:9000; | |
# Include the fastcgi parameter commands. | |
include /etc/nginx/fastcgi_params; | |
# Always execute the index.php from the webroot. | |
fastcgi_param SCRIPT_FILENAME /home/phally/projects/myproject/webroot/index.php; | |
# Set the sub folder name as the script name. | |
fastcgi_param SCRIPT_NAME /myproject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment