【发布时间】:2015-08-16 23:31:01
【问题描述】:
我正在尝试将 cakephp 添加到现有服务器上,但正在使用位置/块。我正在关注 cakephp 食谱上 nginx 部分的漂亮网址。在我的测试环境中,我的服务器块看起来像
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;
}
}
由此,我可以通过 url localhost/tests 运行我的测试控制器
但是,我尝试将 cakephp 添加到的服务器,在域根目录中已经安装了另一个应用程序。
location / {
proxy_pass https://localhost/somepage;
}
我尝试设置一个类似的位置块
location /cakephp {
root /var/www/html/cakephp/app/webroot/;
index index.php;
try_files $uri $uri/ /index.php?args;
}
我知道这行不通,因为它在 url 中寻找 cakephp,但它不存在。由于root设置为/var/www/html/cakephp/app/webroot,当我访问url localhost/cakephp时,它是否在寻找/var/www/html/cakephp/app/webroot/cakephp?
我对如何设置感到困惑。我在某些子目录中阅读了有关 url 重写和 cakephp 的信息,但我不确定这是否是我想要的。现在,应用程序使用http://localhost/someController 运行。我想让应用程序使用 url http://localhost/cakephp/someController 运行。我应该如何设置我的 nginx 配置?
【问题讨论】:
-
@AD7six 访问 url localhost/cakephp,它说没有找到 CakephpController。我创建了控制器并且能够访问正确的网页。这意味着我必须为每个控制器创建一个新的位置块?嗯...有没有办法将 url 设置为使用 localhost/cakephp 而不是 localhost/ ?我猜我将不得不将 /var/www/html/cakephp/ 文件夹放入子目录 /var/www/html/sub/cakephp ,然后在 localhost/sub/someController 中访问它?不确定这是否是正确的路径。