0

I'm trying to set up a Wordpress in a system that has another php application installed, using nginx as web server.

I've simplified my config file to the maximun. The following confi is serving one post of my blog:

server {
    listen 80;
    server_name blog.ct.com;
    root /home/ff/www/blog/;
    index index.php index.html;

    location / {
            try_files $uri $uri/ /index.php?$uri&$args =405;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 64 32k;
            fastcgi_busy_buffers_size 128k;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param APPLICATION_ENV development;
            fastcgi_param HTTP_X_FORWARDED_PROTO https;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
    }
 }

But, due my system's requirements I need to serve the blog from within a sub path (In my final system http://blog.ct.com/ should be serving my custom php app and http://blog.ct.com/vendor should be serving the wordpress blog).

The local root directory from wordpress must be /home/ff/www/blog/ (this cannot be changed, while my custom app's directory is /home/ff/www/myapp/). So I think I need to reserve location / for my custom app, I have to create a location /vendor

If I add /vendor and I return 403 in / (just to debug easier), the browser says 405 (notice the =405 in /vendor, also to debug easier):

location /vendor {
        try_files $uri $uri/ /index.php?$uri&$args =405;
}
location / {
        return 403;
}

So I think nginx is going into location /vendor but is not finding my php script in /home/ff/www/blog/index.php so its returning the fallback 405.

Any idea why this could happen?

How can I achieve to load http://blog.ct.com/vendor as the root from wordpress but keeping http://blog.ct.com/ using another php script?

Freefri
  • 698
  • 7
  • 21

1 Answers1

0

I've found out the following hints that gave me the clue to fix the problem (in case someone has the same problem than me, this may help)

  • Using location /path is not the same as using location ~(/path) (regex have different priority, so maybe they are not being checked in the order you think)
  • Adding error_log /your/path/log/error.log debug; to any location block may help you to see how is nginx serving every request (e.g. to location fastcgi, location \vendor, or the server{ block).
  • alias /var/www/path/vendor works different than root /var/www/path/vendor (check Nginx -- static file serving confusion with root & alias);

    In case of the root directive, full path is appended to the root including the location part, whereas in case of the alias directive, only the portion of the path NOT including the location part is appended to the alias.

  • using rewrite with alias can help you parse the php file you want independent of the path if (!-f $request_filename) { rewrite ^ $document_root/index-wp.php last; }
  • Take care of the SCRIPT_FILENAME you are using (check it with error_log, see above), maybe you need fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; but you are loading fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; so depending on your previous config you may be attaching the document root twice.
  • Two different configurations for fastcgi can be used if you change your index.php file names. E.g. location ~ wp\.php$ { will work with wp.php while location ~ \.php$ { will work with all other php files like index.php.
Freefri
  • 698
  • 7
  • 21