0

I got a PHP application with Core in /srv/myapp/src/www.

This application can have plugins in /srv/myapp/plugins/pluginname.

Plugin's entry point is /srv/myapp/plugins/pluginname/www and corresponding url is something like /pluginname/?arg=value.

I can't figure out how to get a working nginx config with that. My base is:

server {
    listen       80;
    server_name  localhost;

    root   /srv/myapp/src/www;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php;
    }

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

It's working well for all Core related URLs.

I tried to add the following for a given plugin:

 location /plugins/movies {
    alias /srv/myapp/plugins/movies/www;
    try_files $uri /plugins/movies/index.php?$args;
 }

It does work to serve static content (js assets & co) but any URL like /plugins/movies/?id=12 gives a

2016/12/09 15:12:25 [error] 20491#0: *534 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.42.1, server: localhost, request: "GET /plugins/movies/index.php?id=12 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

How can I configure nginx to get it work ?

Manuel VACELET
  • 125
  • 1
  • 9

2 Answers2

0

The filename entered in try_files is always appended to the end of alias or root + location path.

So, with your configuration, URL /plugins/movies/index.php?id=2 would correspond to /srv/myapp/plugins/movies/www/plugins/movies/index.php?id=2.

A quick though not an elegant fix is to use location block like this:

location /plugins/movies {
    alias /srv/myapp/plugins/movies/www;
    try_files $uri ../index.php?$args;
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • If I understand correctly it should even be `try_files $uri ../../index.php?$args;` but neither this form or the one you suggested does the trick. Don't you think there is sth to do with fastcgi config ? – Manuel VACELET Dec 09 '16 at 16:48
0

FWIW here is how I fixed it:

    location /plugins/movies {
        alias /srv/myapp/plugins/movies/www;
        try_files $uri $uri/ index.php;
    }

    location ~ /plugins/movies/(.*\.php)$ {
        alias /srv/myapp/plugins/movies/www/$1;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
Manuel VACELET
  • 125
  • 1
  • 9