Nextcloud behind Nginx – files download instead of preview, apps like Photos/Activity not working

I have no support/technical question and have seen the support category. (Be aware that direct support questions will be deleted.)

on

Which general topic do you have

Hi,

I have a self-hosted Nextcloud instance running on Ubuntu Server with the following stack:

Web server: Nginx
PHP: 8.3 (php-fpm via unix socket)
Database: MariaDB
Nextcloud installed manually (not Docker)
HTTPS working with Let’s Encrypt
Domain: cloudvictoria.duckdns.org

The instance is accessible from both LAN and internet, and login works correctly.

However, I’m experiencing the following issues:

PROBLEMS:

Files are not previewed:
JPG, PNG, PDF, TXT files are downloaded instead of being displayed in the browser
The built-in viewer does not work
Some apps are broken:
“Photos” shows empty content
“Activity” does not load data
“Files” app lists files correctly
Nextcloud admin panel shows warnings:
Issue with “/ocs-provider/” not resolving correctly
Missing HTTP headers warnings
JavaScript / MIME related warnings

WHAT I HAVE VERIFIED:

MIME types are correctly configured in Nginx (image/png, etc.)
Viewer apps are installed and enabled:
files_pdfviewer
viewer
HTTPS is properly configured
trusted_domains and overwrite settings are set correctly in config.php
PHP-FPM is working via socket (/run/php/php8.3-fpm.sock)
Permissions are correct (www-data owns Nextcloud directory)

SYMPTOMS:

Clicking a file triggers download instead of preview
Internal Nextcloud apps relying on OCS endpoints seem broken
It looks like routing or rewrite rules are not fully correct

MY SUSPICION:

This might be related to an incomplete or incorrect Nginx configuration (rewrite rules, location blocks, or handling of index.php and OCS endpoints).

REQUEST:

Can someone provide a minimal, working Nginx configuration for Nextcloud (PHP-FPM)?
What specific Nginx rules are required for:
proper file previews
OCS endpoints (/ocs-provider/)
internal app functionality (Photos, Activity)
How can I verify if requests are correctly routed through index.php?

If needed, I can provide my current Nginx configuration and logs.

Thanks in advance.

The issue you’re describing with files downloading instead of previewing, and OCS requests returning HTML instead of JSON, almost always comes down to Nginx not routing requests through index.php correctly. Nextcloud depends heavily on PHP handling all requests, including paths that look like static files or API endpoints.

The most common cause is a missing or incorrect try_files directive. Your location block needs to pass everything through index.php before serving anything directly. Here’s the config structure that generally works cleanly:

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

location ~ \.php(?:$|/) {
    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_pass unix:/run/php/php8.2-fpm.sock;
    fastcgi_intercept_errors on;
    fastcgi_read_timeout 3600;
}

The OCS API specifically uses paths like /ocs/v2.php/... and Nextcloud’s rewriting must funnel those through index.php rather than treating them as direct file paths. If Nginx tries to serve /ocs/v2.php directly without the proper try_files chain, it either returns a 404 that gets caught as HTML, or the fallback serves the wrong content type.

Also worth checking: make sure your nginx.conf includes MIME type definitions. If application/json isn’t in your types block, some PHP responses get served as application/octet-stream which triggers a download instead of a preview.

What does your current location block look like for the Nextcloud root? That’s usually where the issue sits.

1 Like

Have you seen the official Nginx configuration in the NextcloudAdmin Manual (in the Installation section)?

1 Like