使用ngix-301重定向将cakephp2放在子目录中

使用ngix-301重定向将cakephp2放在子目录中,cakephp,nginx,configuration-files,http-status-code-301,Cakephp,Nginx,Configuration Files,Http Status Code 301,我很难让nginx在子目录中使用CakePHP 我使用nginx是因为我只熟悉Apache,我想学习一些新东西。我的目标是在一个子目录中托管CakePHP My/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.

我很难让nginx在子目录中使用CakePHP

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

My/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/


如果要查看此行为的作用:

首先,这是唯一需要的块

location ~ /randodb(.*) {
    root /var/www/randodb/app/webroot;
    try_files $1 $1/ /index.php?url=$1;
}
在上面的
/
块中,您指定了
root index.html这应该做什么,因为我认为这是不正确的,根应该是一个目录

关于这个街区

fastcgi_param HTTPS on;
include /etc/nginx/include/ssl;
include /etc/nginx/include/php;
php工作正常吗?以前从未见过,你使用的是不同于快速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
    }
}