【问题标题】:CakePHP 2 in a subdirectory with ngix - 301 redirectCakePHP 2 在带有 nginx 的子目录中 - 301 重定向
【发布时间】:2013-06-11 16:13:02
【问题描述】:

我很难让 nginx 在子目录中与 CakePHP 一起工作。

我使用 nginx 是因为我只熟悉 Apache,我想学习一些新东西。我的目标是在子目录中托管 CakePHP。

我的 /etc/nginx/sites-available/default 文件如下所示:

server {

listen 0.0.0.0:80;
root /var/www/;
index index.html index.php;

include /etc/nginx/include/php;
error_page 404 = /404.html;

location / {
    root index.html;
    index index.php index.html index.htm;
    autoindex on;
    try_files $uri $uri/ /index.php;
}

location /randodb {
    if (!-e $request_filename) {
        rewrite ^/randodb(.+)$ /randodb/app/webroot/$1 last;
        break;
    }
}

location /randodb/app/webroot {
    if (!-e $request_filename) {
        rewrite ^/randodb/app/webroot/(.+)$ /randodb/app/webroot/index.php?url=$1 last;
        break;
    }
  }
}

server {

listen 0.0.0.0:443;
root /var/www/;
index index.html index.php;

fastcgi_param HTTPS on;
include /etc/nginx/include/ssl;
include /etc/nginx/include/php;

error_page 404 = /404.html;


}

无论我做什么,/randodb 文件夹中的任何请求都会得到 301 重定向。

它总是将我重定向到http://nginx-php-fastcgi/randodb/

如果您想查看此行为的实际效果:http://www.matgilbert.com/randodb

【问题讨论】:

    标签: cakephp nginx configuration-files http-status-code-301


    【解决方案1】:

    首先这是你需要的唯一块

    location ~ /randodb(.*) {
        root /var/www/randodb/app/webroot;
        try_files $1 $1/ /index.php?url=$1;
    }
    

    在上面的 / 块中,您指定了 root index.html; 这应该做什么,因为我认为这是不正确的,root 应该是一个目录。

    关于这个区块

    fastcgi_param HTTPS on;
    include /etc/nginx/include/ssl;
    include /etc/nginx/include/php;
    

    php 工作正常吗?以前从未见过,你使用的是不是 fast-cgi 或 fpm 的东西?

    然后是 ssl 块,这是我服务器上的 ssl 块

    server {
        listen 443 ssl;
        ssl_certificate /etc/ssl/name.crt;
        ssl_certificate_key /etc/ssl/name.key;
        server_name example.com
        location / {
            # the rest of my config
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      相关资源
      最近更新 更多