简体   繁体   English

CakePHP Htaccess 2 Nginx重写

[英]CakePHP Htaccess 2 Nginx rewrite

We're moving a CakePHP Framework installation to a server where there's an Nginx running. 我们正在将CakePHP Framework安装移动到正在运行Nginx的服务器上。 Previous server had Apache. 先前的服务器具有Apache。 This CakePHP has multiple sub-installations on subfolders which all include the /app/webroot/ folder. CakePHP在子文件夹上有多个子安装,所有子安装都包含/ app / webroot /文件夹。 We've managed to get the index.php working but all the other files located under /app/webroot/ like javascript and CSS don't link up there. 我们设法使index.php正常工作,但是/ app / webroot /下的所有其他文件(如javascript和CSS)都没有链接到那里。

Now, we've tried getting this to work on nginx with multiple different variations. 现在,我们尝试使它在具有多个不同变体的nginx上运行。 The problem is, the site loads up PHP files and clean URL'S work. 问题是,该网站加载了PHP文件并清理了URL的工作。 Loading CSS and JS files which are located under /app/webroot/ don't. 不会加载位于/ app / webroot /下的CSS和JS文件。

We're trying to set up the root to subdomain.example.com where there's an index.php with a header() function to redirect the user to a folder, where there's CakePHP. 我们正在尝试将根目录设置为subdomain.example.com,其中存在带有header()函数的index.php以将用户重定向到文件夹,其中存在CakePHP。 Basically multiple sites under sub folders. 子文件夹下基本上有多个站点。 So the CakePHP sites are http://subdomain.example.com/subfolder 因此CakePHP网站是http://subdomain.example.com/subfolder

Here's the nginx conf we're trying. 这是我们正在尝试的nginx conf。 I've been trying various different options with no effect. 我一直在尝试各种不同的选择,但没有效果。

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;
    }
}

app/webroot/ will be your server root. app / webroot /将是您的服务器根目录。 And separate location for process index.php file. 并为进程index.php文件提供单独的位置。

Example: 例:

server {
    listen   80;
    server_name yourserver.com;

    root   /web/path/;
    index  index.php;

    location / {
        rewrite ^(/.*)$ /app/webroot$1 break;
        try_files $uri $uri/ /app/webroot/index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM