脚本宝典收集整理的这篇文章主要介绍了CakePHP在一个使用nginx的子目录中(重写规则?),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
目前我有:
worker_PRocesses 1; events { worker_connections 1024; } http { include mime.tyPEs; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root htML; index index.PHP index.html index.htm; } location /basic_cake/ { index index.PHP; if (-f $request_filename) { break; } if (!-f $request_filename) { rewrITe ^/basic_cake/(.+)$/basic_cake/index.PHP?url=$1 last; break; } } location /cake_test/ { index index.PHP; if (-f $request_filename) { break; } if (!-f $request_filename) { rewrite ^/cake_test/(.+)$/cake_test/index.PHP?url=$1 last; break; } } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.PHP${ root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_SCRIPT_NAME; include fastcgi_params; } } server { listen 8081; server_name localhost; root /srv/http/html/xsp; location / { index index.html index.htm index.aspx default.aspx; } location ~ \.(aspx|asmx|ashx|aSAX|ascx|SOAp|rem|axd|cs|config|dll)${ fastcgi_pass 127.0.0.1:9001; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
我遇到的问题是css和图像不会从webroot加载.相反,如果我访问http://localhost/basic_cake/css/cake.generic.css,我会得到一个页面告诉我:
有没有人对如何解决这个问题有任何想法?
所以,假设我有/ VAR / www / html / cakeprj中的cakePHP副本,我的WWWROOT是/ var / www / html:
> Nginx主机配置
# that's for all other content on the web host location / { root /var/www/html; autoindex off; index index.PHP index.html index.htm; ... } # that's for cakePHP location /cakeprj { rewrite ^/cakeprj$/cakeprj/ permanent; rewrite ^/cakeprj/(.+)$/$1 break; root /var/www/html/cakeprj/app/webroot; try_files $uri /$uri/ @cakePHP; } # that's for all other PHP scripts on the web host location ~ \.PHP${ root /var/www/html; fastcgi_pass unix:/var/lib/fcgi/PHP-fcgi.socket; ... include /etc/Nginx/fastcgi_params; } # that's for cakePHP execution location @cakePHP { set $q $REQUEST_URI; if ($request_uri ~ "^/cakeprj(.+)$") { set $q $1; } fastcgi_param SCRIPT_FILENAME /var/www/html/cakeprj/app/webroot/index.PHP; fastcgi_param QUERY_STRING url=$q; fastcgi_pass unix:/var/lib/fcgi/PHP-fcgi.socket; include /etc/Nginx/fastcgi_params; }
> app / config / core.PHP中的cakePHP配置
Configure::write('App.base','/cakeprj'); Configure::write('App.baseUrl','/cakeprj/'); // seems like it doesn't matter anymore
…并且瞧 – 你正确地为Nginx服务cakePHP静态文件,正确地传递给cakePHP调度程序的url以及正确生成url的cakePHP.
以上是脚本宝典为你收集整理的CakePHP在一个使用nginx的子目录中(重写规则?)全部内容,希望文章能够帮你解决CakePHP在一个使用nginx的子目录中(重写规则?)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。