How do I configure nginx rewrite rules to get CakePHP working on CentOS?

前端 未结 6 2091
清歌不尽
清歌不尽 2021-01-31 12:42

Hi somebody please help me out, I’m trying to setup a cakephp environment on a Centos server running Nginx with Fact CGI. I already have a wordpress site running on the server a

6条回答
  •  攒了一身酷
    2021-01-31 12:58

    Please use below code in

    vi /etc/nginx/sites-available/domainname.com

    server { 
    server_name  cakeapp.example.com;
    root   /var/www/vhosts/cake/app/webroot;
    access_log  /var/log/nginx/cakeapp.access.log;
    error_log   /var/log/nginx/cakeapp.error.log;
    
    listen       80;
    rewrite_log on;
    
    # rewrite rules for cakephp
    location / {
        index  index.php index.html;
    
        # If the file exists as a static file serve it 
        # directly without running all
        # the other rewite tests on it
        if (-f $request_filename) { 
            break; 
        }
        if (!-f $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;
            break;
        }
    }
    
    location ~* \favicon.ico$ {
        expires 6m;
    }
    location ~ ^/img/ { 
        expires 7d; 
    } 
    
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SERVER_NAME $host;
    }
    
    location ~ /\.ht {
        deny  all;
    }
    

    }

    Its working for me.

提交回复
热议问题