Nextcloud Pretty URLs - can't get rid of index.php

I followed instructions over at Docker Hub to set up a Nextcloud “Base version - FPM” container (built with cron added) along with abiosoft’s caddy container. The caddyfile settings I used are essentially the ones from examples/Caddyfile at master · caddyserver/examples · GitHub. Nextcloud appears to work just as fine with this setup as it did before when I used caddy as a reverse proxy only but the url now always includes index.php/, as in
nc.mydomain.com/index.php/login instead of nc.mydomain.com/login. Apparently other users got it right (Remove index.php from {uri} (rewrite)). Is there anything obvious that I’m missing or that I am doing wrong?

My Caddyfile currently contains:

nc.mydomain.com {

        root /srv/nextcloud

        log /Caddylog/nextcloud_access.log {
                rotate_size 10 # Rotate after 10 MB
                rotate_age  14  # Keep log files for 14 days
                rotate_keep 10  # Keep at most 10 log files
        }
        errors stdout

        fastcgi / nextcloud:9000 php {
                root /var/www/html
        }

        # checks for images
        rewrite {
                ext .svg .gif .png .html .ttf .woff .ico .jpg .jpeg
                r ^/index.php/(.+)$
                to /{1} /index.php?{1}
        }

        rewrite {
                r ^/index.php/.*$
                to /index.php?{query}
        }

        # client support (e.g. os x calendar / contacts)
        redir /.well-known/carddav /remote.php/carddav 301
        redir /.well-known/caldav /remote.php/caldav 301

        # remove trailing / as it causes errors with php-fpm
        rewrite {
                r ^/remote.php/(webdav|caldav|carddav|dav)(\/?)$
                to /remote.php/{1}
        }

        rewrite {
                r ^/remote.php/(webdav|caldav|carddav|dav)/(.+?)(\/?)$
                to /remote.php/{1}/{2}
        }

        rewrite {
                r ^/public.php/(.+?)(\/?)$
                to /public.php/(.+?)(\/?)$
        }

        # .htaccess / data / config / ... shouldn't be accessible from outside
        status 403 {
                /.htacces
                /data
                /config
                /db_structure
                /.xml
                /README
        }

        header / Strict-Transport-Security "max-age=31536000;"


        tls me@myhost.com
}

The relevant section of the docker-compose.yml is

volumes:
  caddy-certs:
  nextcloud-data:

services:
  caddy:
    image: abiosoft/caddy
    restart: always
    depends_on:
      - nextcloud
    volumes:
      - ./Caddyfile:/etc/Caddyfile
      - ./Caddylog:/Caddylog
      - caddy-certs:/root/.caddy
      - nextcloud-data:/srv/nextcloud:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "443:443"
      - "80:80"
           
  nextcloud:
    build: .
    restart: always
    volumes:
      - nextcloud-data:/var/www/html

hi

you might want to check out https://caddyserver.com/docs/ext

Try

rewrite {
if {path} starts_with .
if {path} not_starts_with .well-known
to error/index.html
}
rewrite {
if {file} not favicon.ico
to {path} {path}/ /index.php?{path}&{query}
}

That is what I use for drupal which has similar setup that everything should be redirected to index.php. May not be exactly what Nextcloud is looking for but it may be a good place to start.

Thanks for the suggestions. I’ll have to look into it some more later on. For now I have reverted to using Caddy as a reverse proxy and letting Apache handle the rewrites.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.