【发布时间】:2015-02-08 10:44:15
【问题描述】:
我们正在将 CakePHP 框架安装移动到运行 Nginx 的服务器上。以前的服务器有 Apache。这个 CakePHP 在包含 /app/webroot/ 文件夹的子文件夹上有多个子安装。我们已经设法让 index.php 正常工作,但位于 /app/webroot/ 下的所有其他文件(如 javascript 和 CSS)都没有链接到那里。
现在,我们已经尝试让它在具有多种不同变体的 nginx 上工作。问题是,该站点加载了 PHP 文件并清理了 URL 的工作。不加载位于 /app/webroot/ 下的 CSS 和 JS 文件。
我们正在尝试将根目录设置为 subdomain.example.com,其中有一个带有 header() 函数的 index.php,用于将用户重定向到一个文件夹,其中有 CakePHP。基本上子文件夹下的多个站点。所以 CakePHP 网站是http://subdomain.example.com/subfolder
这是我们正在尝试的 nginx 配置。我一直在尝试各种不同的选项,但没有任何效果。
server {
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen 80;
server_name example.com www.example.com subdomain.example.com;
access_log /home/example.com/logs/access.log;
error_log /home/example.com/logs/error.log error;
root /home/example.com/public_html/;
index index.php;
gzip_static on;
location /subfolder {
root /home/example.com/public_html/subfolder/;
index index.php;
rewrite ^/subfolder/(/.*)$ /app/webroot$1 break;
try_files $uri $uri/ /subfolder/app/webroot/index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_comles $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/example.com-php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
【问题讨论】:
-
1.
/home/example.com/public_html/cake1/app/webroot/- 第一个蛋糕,需要打开example.com/cake1/,/home/example.com/public_html/cake2/app/webroot/- 第二个蛋糕,需要打开example.com/cake2/等等。这是你的文件夹结构吗? 2. images 文件夹在哪里,/home/example.com/public_html/images/(并在安装之间共享)或/home/example.com/public_html/cake2/images/或/home/example.com/public_html/cake2/app/webroot/images/?
标签: apache .htaccess cakephp nginx