nextcloud / nextcloud/documentation

nginx config handles routes with embedded `.php` in them differently than apache config

Open
#11,951 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop bug feature: install and update manual: admin
Dominant language
JavaScript
Stars
628
Forks
2.5k
Avg merge
2d 11h
Merged PRs (30d)
135

Description

Using Power Ampache 2 android client to connect to my Nextcloud Music App, I was unable to connect due to nginx error.

92.xxx.yyy.zzz - - [23/Jun/2024:18:11:56 +0200] "GET /apps/music/ampache/server/json.server.php?action=handshake&auth=0dc8eab854xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx289e9ded5423&user=xxxxxxx&timestamp=1719159117 HTTP/2.0" 404 146 "-" "PowerAmpache2-1.00-60-fdroid"

It appears that issue is related to try_files directive in the nginx configuration file when using Ampache API, like described here : Ampache api with nextcloud served by nginx gets 404 when following nextcloud admin docs.

After some help from Ampache dev (see here), adding a new location for /apps/music/ampache/server/ like below setting in nginx configuration file solves the issue :

    location ~ ^/apps/music/ampache/server/.*\.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        set $path_info $fastcgi_path_info;

        try_files $fastcgi_script_name /index.php$fastcgi_script_name?$args;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param HTTPS on;

        fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
        fastcgi_param front_controller_active true;     # Enable pretty urls
        fastcgi_pass php-handler;

        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

    # Ensure this block, which passes PHP files to the PHP process, is above the blocks
    # which handle static assets (as seen below). If this block is not declared first,
    # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
    # to the URI, resulting in a HTTP 500 error response.
    location ~ \.php(?:$|/) {
        # Required for legacy support
        rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;

        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        set $path_info $fastcgi_path_info;

        try_files $fastcgi_script_name =404;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param HTTPS on;

        fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
        fastcgi_param front_controller_active true;     # Enable pretty urls
        fastcgi_pass php-handler;

        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

So it would probably be good to amend the following documentation with the above example, probably in the following documentation : https://docs.nextcloud.com/server/21/admin_manual/installation/nginx.html#nextcloud-in-the-webroot-of-nginx, in the Tips and Tricks section, when using Nextcloud Music App from Ampache client and using nginx as proxy server.


Note I was using the following versions when experiencing this issue :

  • Nextcloud 29.0.1
  • Music 2.0.0
  • Operating system and version: Armbian 24.5.1 bookworm (x32)
  • Apache or nginx version : 1.20.2
  • PHP version : 8.1.16
  • Power Apache 2 version : 1.00-60-fdroid

Running docker images provided by Linuxserver.io . File modified is Nextcloud/config/nginx/site-confs/default.conf

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the Nextcloud nginx installation documentation page and inspect the “Tips and Tricks” section for the webroot configuration. Compare the reported Ampache route behavior and proposed nginx example with the existing guidance; done means the relevant configuration advice is documented clearly for Music App users behind nginx.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.