Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to configure both CakePHP and a wordpress blog on the same server.

CakePHP here: http://site.com/

Wordpress blog here: http://site.com/blog/

What works: The whole CakePHP app and going to /blog/.

What doesn't work: Going to /blog/permalink/. It gives a CakePHP 404 page.

The /blog/ works with or without the "# Blog config" below. How do I make /blog/permalink/ work? I'm used to working with Apache.

edit: It was suggested that my question is a duplicate of this post however if I use that solution or my solution (commented # Blog config) below it gives me a CakePHP 404 page. This means that /blog/permalink/ doesn't hit the wordpress's index.php.

upstream backend {
    server unix:/var/www/apps/appname/tmp/php.sock;
}

server {
    listen 80 default;
    root    /var/www/apps/appname/public/app/webroot;
    index   index.php index.html index.htm;

    server_tokens off;

    access_log  /var/www/apps/appname/logs/access.log;
    error_log   /var/www/apps/appname/logs/error.log;

    client_max_body_size 20M;

    rewrite_log on;

    # Blog config
    location /blog/ {
        try_files $uri $uri/ /blog/index.php?$args;
    }

    # Not found this on disk? 
    # Feed to CakePHP for further processing!
    if (!-e $request_filename) {
        rewrite ^/(.+)$ /index.php last;
        break;
    }

    # Pass the PHP scripts to FastCGI server
    # listening on 127.0.0.1:9000
    location ~ \.php$ {
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_intercept_errors on; # to support 404s for PHP files not found
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # Static files.
    # Set expire headers, Turn off access log
    location ~* \favicon.ico$ {
        access_log off;
        expires 1d;
        add_header Cache-Control public;
    }
    location ~ ^/(img|cjs|ccss)/ {
        access_log off;
        expires 7d;
        add_header Cache-Control public;
    }

    location ~ ^/(php_status|php_ping)$ {
      fastcgi_pass backend;
      fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
      include fastcgi_params;
      allow 127.0.0.1;
      deny all;
    }

    location /nginx_status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }

    # Deny access to .htaccess files,
    # git & svn repositories, etc
    location ~ /(\.ht|\.git|\.svn) {
        deny  all;
    }
}
share|improve this question
    
Sorry about the accidental mark as duplicate. I misread your config on first reading and didn't realize that you'd already done what was in the answer there. –  Michael Hampton May 29 '13 at 21:39
    
Ok... I'll let this one pass... ;) –  iDev247 May 30 '13 at 8:03
add comment

1 Answer 1

up vote 1 down vote accepted

This looks like your problem. It rewrites all URLs, not just those destined for CakePHP. This is one of the most common nginx misconfigurations.

    # Not found this on disk? 
    # Feed to CakePHP for further processing!
    if (!-e $request_filename) {
        rewrite ^/(.+)$ /index.php last;
        break;
    }

This should be deleted and replaced with an equivalent try_files in your location / block (which you don't seem to have, so create one).

    location / {
        try_files $uri $uri/ /index.php;
    }
share|improve this answer
    
Awesome! That seems to have worked perfectly. Thanks :) –  iDev247 May 29 '13 at 21:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.