Docker: Nextcloud-FPM behind Nginx Proxy Manager - do I need another nginx container?


I currently have Nextcloud 23 running as a Docker container using the apache-image.

However, there is also an nginx proxy manager container in front of the nextcloud container in order to do the reverse proxy management for all my subdomains.

As I have two reverse proxies lined up (first nginx proxy manager, then apache in the docker container), I thought it might be possible to spare the apache and switch to the fpm image.

However, I couldn’t find a way to route directly from the nginx proxy manager to the nextcloud-fpm image. Is this possible?

The examples all have another nginx instance in the docker-compose.yml, but that way I would just replace apache with nginx wich can be a little advantage, but the real advantage would be to remove one layer of reverse proxies…

Thank you in advance for your help!

Same issue here, but different reason.

Basically I can’t get nextcloud:FPM to work with Nginx when docker-compose starts nextcloud:FPM and Nginx is a normal Linux service.

So same issue in that I use Nginx and do not want another Apache (or any HTTP) in the docker-compose.

So I second the question: “I couldn’t find a way to route directly from the nginx proxy manager to the nextcloud-fpm image. Is this possible?” I’ve been trying to configure Nginx since it manages other subdomains not using Nginx Proxy Manger directly.

1 Like

Out of curiosity I just tried to run nextcloud:fpm behind another nginx container.

Like this:
NPM > NGinx Container > Nextcloud FPM Container

Interestingly, the “default” setup with NPM > Nextcloud Apache Container finished loading in about 5 seconds while the above setup took about 7-8 seconds.

So I still would be interested to try it with just NPM > Nextcloud FPM Container but using the fpm behind another Nginx container has no advantage compared to the default setup.

Nextcloud:FPM requires port 9000. So if everything was set up correctly in NGINX PM it may work. I am new to NPM and wasn’t able to get it to work properly. So I went with the basic Nextcloud image.

I was happy to find this thread as I am struggling with the exact same problem but it is discouraging to find out that none of you has managed to get it to work.

Did anyone since?

Edit: Just to add some more info.

I added to my environment variables of the nextcloud docker setup the following two, one for the fastcgi and one to tell NPM the nextcloud port:


But no luck.

Go to Nginx Proxy Manager > Advanced and specify this configuration:

        # set max upload size
        client_max_body_size 512M;
        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/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                         "noindex, nofollow" 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;

        # Path to the root of your installation
        root /var/www/html;

        # Specify how to handle directories -- specifying `/index.php$request_uri`
        # here as the fallback means that Nginx always exhibits the desired behaviour
        # when a client requests a path that corresponds to a directory that exists
        # on the server. In particular, if that directory contains an index.php file,
        # that file is correctly served; if it doesn't, then the request is passed to
        # the front-end controller. This consistent behaviour means that we don't need
        # to specify custom rules for certain paths (e.g. images and other assets,
        # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
        # `try_files $uri $uri/ /index.php$request_uri`
        # always provides the desired behaviour.
        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(?:$|/) {
            # 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 nextcloud:9000;

            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;

        location ~ \.(?:css|js|svg|gif)$ {
            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 ~ \.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;

replace nextcloud:9000 for the name of your container in your network:

fastcgi_pass nextcloud:9000;

My docker-compose:

version: '3'

    image: 'jc21/nginx-proxy-manager:latest'
    container_name: nginx-proxy-manager
      - test
    restart: unless-stopped
      - '80:80'
      - '43013:81'
      - '443:443'
      REAL_IP_HEADER: "X-Real-IP"
      - /root/data:/data
      - /root/letsencrypt:/etc/letsencrypt
      - "share:/var/www/html:ro,Z"
          cpus: '1'
          memory: 256M

    image: "nextcloud:fpm-alpine"
    container_name: "nextcloud"
      - test
      - "share:/var/www/html:rw,Z"
      - "/home/ikrell/nextcloud/data:/var/www/html/data:rw,Z"
          cpus: '1'
          memory: 256M

  share: {}