New fpm-docker installation won't work - can't find error

Hi there,

I just installed a fresh Nextcloud installation using Docker-Compose, but unfortunately it doesn’t work (FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream). Maybe someone has an idea or a suggestion where the error is.

i store all data under: /srv/services/nextcloud-data/
i got two webroot directories because my nginx must handle different fpm-workers, so the main webroot of nginx-server ist /var/www mapped to real-path under /srv/http
nextcloud webfiles are under /srv/http/nextcloud
root of nextcloud-fpm is /var/www/html mapped to realpath /srv/http/nextcloud

nginx → /var/www/nextcloud ← access for static files without php
nextcloud-fpm → /var/www/html ← access for php-parser from nextcloud instance

if i just set one root /var/www/nextcloud, then i got this error in my nginx-docker-instance-log:

[14/Feb/2022:13:43:52 +0000] “GET / HTTP/2.0” 404 36 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36” “-”
2022/02/14 13:44:01 [error] 31#31: *1 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client:, server: nextcloud.internal, request: “GET /index.php HTTP/2.0”, upstream: “fastcgi://”, host: “nextcloud.internal”

and nextcloud-instance show me:

14/Feb/2022:14:18:01 +0000 “GET /index.php” 404

if i add second root under php-location:
root /var/www/html; # because nextcloud docker is mapped to /srv/http/nextcloud directly

then the web-nginx-log says:

[14/Feb/2022:14:15:36 +0000] “GET / HTTP/2.0” 404 174 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36” “-”

and nextcloud-log say nothing!

here my docker-compose:

version: '3.8'

    container_name: postgres
    hostname: postgres
    image: postgres:alpine
    restart: unless-stopped
      - /srv/services/postgres-data:/var/lib/postgresql/data
      - "5432:5432/tcp"
      test: pg_isready --dbname=postgres --host=localhost --username=postgres
      interval: 10s
      timeout: 5s
      retries: 5

    container_name: web
    hostname: web
    image: nginx:alpine
    restart: unless-stopped
    working_dir: /var/www
      - "80:80"
      - "443:443"
      - /srv/services/nginx/certs:/etc/nginx/certs
      - /srv/http:/var/www
      - /srv/services/nginx/conf.d:/etc/nginx/conf.d
      - nextcloud

    container_name: nextcloud
    hostname: nextcloud
    image: nextcloud:fpm-alpine
    restart: unless-stopped
       - /srv/http/nextcloud:/var/www/html
       - /srv/services/nextcload-data:/var/www/data
    working_dir: /var/www/html
      - VIRTUAL_HOST=nextcloud.internal
      - LETSENCRYPT_HOST=nextcloud.internal
      - NEXTCLOUD_TRUSTED_DOMAINS=nextcloud.internal
      - POSTGRES_DB=nextcloud
      - POSTGRES_HOST=postgres
      - POSTGRES_USER=nextcloud
      - postgres

    container_name: wiki
    hostname: wiki
    image: webdevops/php-nginx:8.0-alpine
    restart: unless-stopped
       - /srv/http/wiki:/var/www
    working_dir: /var/www
      - postgres

and here my nginx-nextcloud.conf (i get the config original from docs:

upstream php-handler {
    server nextcloud:9000;

server {
    listen      80;
    listen      [::]:80;
    server_name .nextcloud.internal;
    return      301 https://nextcloud.internal$request_uri;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name .nextcloud.internal;

    include conf.d/params-ssl;

    ssl_certificate     /etc/nginx/certs/$host-bundle.cert.pem;
    ssl_certificate_key /etc/nginx/certs/$host.key.pem;

    # set max upload size and increase upload timeout:
    client_max_body_size 512M;
    client_body_timeout 300s;
    fastcgi_buffers 64 4K;

    # Enable gzip but do not remove ETag headers
    gzip on;
    gzip_vary on;
    gzip_comp_level 4;
    gzip_min_length 256;
    gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
    gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/ application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

    # Pagespeed is not supported by Nextcloud, so if your server is built
    # with the `ngx_pagespeed` module, uncomment this line to disable it.
    #pagespeed off;

    # HTTP response headers borrowed from Nextcloud `.htaccess`
    add_header Referrer-Policy                      "no-referrer"   always;
    add_header X-Content-Type-Options               "nosniff"       always;
    add_header X-Download-Options                   "noopen"        always;
    add_header X-Frame-Options                      "SAMEORIGIN"    always;
    add_header X-Permitted-Cross-Domain-Policies    "none"          always;
    add_header X-Robots-Tag                         "none"          always;
    add_header X-XSS-Protection                     "1; mode=block" always;

    # Remove X-Powered-By, which is an information leak
    fastcgi_hide_header X-Powered-By;

    root   /var/www/nextcloud; # webroot for css/js files

    index index.php index.html /index.php$request_uri;

    # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
    location = / {
        if ( $http_user_agent ~ ^DavClnt ) {
            return 302 /remote.php/webdav/$is_args$args;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    # Make a regex exception for `/.well-known` so that clients can still
    # access it despite the existence of the regex rule
    # `location ~ /(\.|autotest|...)` which would otherwise handle requests
    # for `/.well-known`.
    location ^~ /.well-known {
        # The rules in this block are an adaptation of the rules
        # in `.htaccess` that concern `/.well-known`.

        location = /.well-known/carddav { return 301 /remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /remote.php/dav/; }

        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

        # Let Nextcloud's API for `/.well-known` URIs handle all other
        # requests by passing them to the front-end controller.
        return 301 /index.php$request_uri;

    # Rules borrowed from `.htaccess` to hide certain paths from clients
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }

    # 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(?:$|/) {
        root   /var/www/html;  # if not set, i got error: "FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream"

        # 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;

        fastcgi_max_temp_file_size 0;

    location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite)$ {
        try_files $uri /index.php$request_uri;
        expires 6M;         # Cache-Control policy borrowed from `.htaccess`
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;

    location ~ \.woff2?$ {
        try_files $uri /index.php$request_uri;
        expires 7d;         # Cache-Control policy borrowed from `.htaccess`
        access_log off;     # Optional: Don't log access to assets

    # Rule borrowed from `.htaccess`
    location /remote {
        return 301 /remote.php$request_uri;

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


any ideas?

Hi, I have a similar problem, did you manage to fix this?

My nginx logs say that my nginx.conf is wrong format (either that upstream cant be at the top of the file or that Im missing the http header).

Im also using the original nginx config from the docs :frowning:

When I wrap the whole nginx.conf file in the http {} tag, the webserver does work, BUT i can only see index.php in plain text, no nextcloud logo, bg color or anything.