0
Answered

Provide Nginx Config Example

ken 2 years ago updated by Vlad R 2 years ago 6

Hello,

I am curious if there is any plans to include a example Nginx configuration? More and more people are ditching Apache for Nginx. The only examples I could find were for people using Nginx as a reverse proxy to Apache. Almost everything is working except for the weblinks, they either return 404 or a generic error page in Chrome. I would assume this is due to the use of mod_rewrite in the .htaccess files, I haven't been able to successfully convert them to Nginx. Or if a user has a working example they could post up for users to reference would be EXTREMELY helpful. From looking around there is a lot of people looking for this.

Answer

Answer

For everybody configuring PHP on NGINX: please use the official NGINX documentation, guides and examples: "https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/".

While FileRun works with an incomplete/incorrect configuration, access via WebDAV (includes Nextcloud apps) won't work. The configuration example above includes correct handling of PATH_INFO and enables FileRun's URL "http://hostname/dav.php/" (note trailing slash) to work properly.

I reinstalled FileRun, and now everything is working as expected even with Nginx. When I clean up my Nginx config I will post it for others to reference.

Answered

If having trouble to connect to FileRun on NGINX using the mobile apps, use this: https://stackoverflow.com/questions/26374986/nginx-returns-a-404-for-urls-like-index-php-some-path

Here is my Nginx Config. This has been edited down for this post to remove personal stuff, but I believe it should work.
Also, I use a PHP FPM Pool for FileRun, which I don't show here.

WebDav works with this config as tested using cadaver, but the first folder shown is @Home and not My Files - confusing, yes!!

server
{    
    listen 443 ssl;
    server_name example.com;

    ssl on;
    ssl_certificate     /etc/nginx/certs/example.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/example.com/key.pem;

    server_tokens off;

    root /var/www/nginx/html;
    index index.html;

    location /
    {
        root /var/www/nginx/html;
        try_files $uri $uri/ /404.html;
    }

    location /.well-known/acme-challenge
    {
        allow all;
    }

    location /filerun
    {
        ## Not Needed ##
        #dav_methods PUT DELETE MKCOL COPY MOVE;
        #dav_ext_methods PROPFIND OPTIONS;
        #dav_access user:rw;

        root /var/www/nginx;
        try_files $uri $uri/ =404;

        index index.php index.html;

        keepalive_requests    10;
        keepalive_timeout     60 60;

        client_max_body_size 800M;
        client_body_buffer_size 128k;

        if (!-e $request_filename)
        {
            rewrite ^(.*)$ /index.php break;
        }

        # PHP configuration
        location ~ \.php(?:$|/)
        {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            include fastcgi_params;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;

            #Avoid sending the security headers twice
            fastcgi_param modHeadersAvailable true;
            fastcgi_param front_controller_active true;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;

            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
    }
}

Answer

For everybody configuring PHP on NGINX: please use the official NGINX documentation, guides and examples: "https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/".

While FileRun works with an incomplete/incorrect configuration, access via WebDAV (includes Nextcloud apps) won't work. The configuration example above includes correct handling of PATH_INFO and enables FileRun's URL "http://hostname/dav.php/" (note trailing slash) to work properly.

Should I copy the example at "https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/" to my_server.conf? Now I can view "http://my_ip/dav.php" through webpage but I still can't log in by Windows Explorer or software.

Strongly hope anyone can post an example of nginx conf.

Please read: http://docs.filerun.com/webdav You have to append / after dav.php. Windows web folders is not supported unfortunately, as it is not standards compliant.