cakephp - Subfolder installation -
i'm trying add on cakephp on existing server, location / block being used. i'm following pretty url on nginx section on cakephp cookbook. on test environment, have server block looking
server { listen 80; server_name localhost; access_log /var/www/html/log/access.log; error_log /var/www/html/log/error.log; location / { root /var/www/html/cakephp/app/webroot/; index index.php; try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { root /var/www/html/cakephp/app/webroot/; index index.php; try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param script_filename $document_root$fastcgi_script_name; } }
from this, i'm able run testscontroller through url localhost/tests
however, server i'm trying add cakephp to, there application installed @ domain root.
location / { proxy_pass https://localhost/somepage; }
i tried setting location block like
location /cakephp { root /var/www/html/cakephp/app/webroot/; index index.php; try_files $uri $uri/ /index.php?args; }
i understand wouldn't work because it's looking cakephp in url, wouldn't there. since root set /var/www/html/cakephp/app/webroot, when access url localhost/cakephp, looking /var/www/html/cakephp/app/webroot/cakephp?
i'm getting confused how set up. read url rewriting , cakephp running in subdirectory, i'm not sure if that's looking for. right now, application runs http://localhost/somecontroller. have the application run url http://localhost/cakephp/somecontroller. how should setup nginx config?
fix static files first
with config in question, you'll find nothing works - not requests static files.
consider:
server { ... root /wherever/; error_log /tmp/cakephp.err.log debug; # <- add location /cakephp { root /var/www/html/cakephp/app/webroot/; index index.php; try_files $uri $uri/ /index.php?args; } }
this produce:
$ curl -i http://cakephp.dev/cakephp/favicon.ico http/1.1 404 not found
the debug log clarify why occurs:
-> cat /tmp/cakephp.err.log ... 2015/08/23 10:53:43 [debug] 9754#0: *87 http script var: "/cakephp/favicon.ico" 2015/08/23 10:53:43 [debug] 9754#0: *87 trying use file: "/cakephp/favicon.ico" "/var/www/html/cakephp/app/webroot/cakephp/favicon.ico"
nginx using whole url path file, not bit after location prefix. understanding difference between root directive , alias directive important, , common question (random result, there many).
so, fixing first:
server { ... error_log /tmp/cakephp.err.log debug; location /cakephp { alias /var/www/html/cakephp/app/webroot/; # <- alias, not root index index.php; try_files $uri $uri/ /index.php?args; } }
will produce:
$ curl -i http://cakephp.dev/cakephp/favicon.ico http/1.1 200 ok
then fix php requests
the problem php requests more or less same thing; though request finds right php file it's configured such cakephp assume it's installed in root. there various solutions - here's one:
server { ... error_log /tmp/cakephp.err.log debug; location /cakephp { alias /var/www/html/cakephp/app/webroot/; index index.php; try_files $uri $uri/ /cakephp/index.php; # <- redirect actual equivalent request } location /cakephp/index.php { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; # explicit script filename fastcgi_param script_filename /var/www/html/cakephp/app/webroot/index.php; } }
in way static files , dynamic requests both work - , environment variables cakephp receives such understands root of application /cakephp/
.
Comments
Post a Comment