0

I'm trying to set up FSyncMS (a minimal php weave/sync1.1 server in php) on a server. I've gotten as far as setting up the back-end but I'm running into the problem that I can't find a way to properly have nginx (my front-end web server) pass the requests to the php script.

The sync client passes parameters to the server with slash parameter URLs:

scheme://server.com/user/1.0/a

Which should be translated to:

scheme://server.com/index.php/user/1.0/a

And passed to the back-end as index.php with parameters everything after that. Unfortunately nginx happily sees index.php/user/1.0/a as the path, instead of index.php as the path and /user/1.0/a as parameters. Result: a predictable 404...

More info on the sync server implementation (in German, unfortunately): http://www.ohnekontur.de/2011/07/24/how-to-install-fsyncms-firefox-sync-eigener-server/

How do I get around this problem?

EDIT: nginx config:

server {
    listen 80;
    server_name sync.server.com;
    return 301 https://$server_name$request_uri;  # enforce https
}

server {
    listen 443 ssl;
    server_name sync.server.com;

    ssl_certificate /srv/syncserver/server.com.combined.crt;
    ssl_certificate_key /srv/syncserver/server.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers !aNULL:!LOW:!MD5:!EXP:CAMELLIA:AES256:HIGH:AES128:RC4:!3DES:!SEED;
    ssl_prefer_server_ciphers on;

    access_log /srv/www/sync/logs/access.log;
    error_log /srv/www/sync/logs/error.log;

    root /srv/www/sync/public_html;
    index index.php index.html;

    location / {
        ssi on;
        index index.php index.shtml index.html index.htm;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

2 Answers2

0

You are missing your try_files to divert requests to PHP when no matching static assets are present.

For instance:

location / {
    try_files $uri $uri/ /index.php;
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Thanks, that changed something at least. Instead of the 404, I now get http 400 errors ("Bad request")... So something would still be missing or incorrect. – Mark Straver Jul 28 '14 at 13:59
  • Check your error log, then. – Michael Hampton Jul 28 '14 at 14:00
  • Well, the error log doesn't show anything. The 400 is thrown by the script, because the parameters are still not properly passed to it. "Not a valid sync request". explicitly stating index.php in the URL still gives a 404 as well (which, according to fsyncms should work), so the path is still not converted to parameters properly. `83.227.2.68 - - [28/Jul/2014:14:01:29 +0000] "GET /index.php/user/1.0/a HTTP/1.1" 404`, and without index.php I get `83.227.2.68 - - [28/Jul/2014:14:03:28 +0000] "GET /user/1.0/a HTTP/1.1" 400` – Mark Straver Jul 28 '14 at 14:09
  • The problem lies with the script, then. The URL is being passed to it correctly. There should be no need to have "index.php" appear in the URL when the PHP script receives it. Check with the script author. – Michael Hampton Jul 28 '14 at 14:09
  • I don't see why it would be the script, since it works on Apache and lighttpd, apparently. nginx obviously doesn't handle index.php/param/param/param with my current setup, so I do think it's an nginx config issue. – Mark Straver Jul 28 '14 at 14:14
  • Check your `/etc/nginx/fastcgi_params`. If it is the default that came with nginx, then nginx is fine, and the script really is broken. – Michael Hampton Jul 28 '14 at 14:16
0

Posting my own answer here for future reference. After getting some more help with try_files from a colleague and examining the script in more detail, the problem is twofold:

1) fsyncms doesn't like being in the root of a host. it would clean up the path by removing a trailing slash, but in case of / that would leave an empty path string, which tripped an error.

2) try_files was needed (Thanks, Michael, for the pointer!) but the actual rule needed was a little different to pass the arguments (e.g. when placing the fsync scripts in /fsync on the server):

try_files $uri $uri/ /fsync/index.php/$args;

After which a server URI of http(s)://server.com/fsync/ is accepted by the client.