Skip to content

Changing localhost to your TLD domain for use with nginx reverse proxy #846

Closed

Description

@jiveman

I setup the latest nextcloud with docker-compose like the example shows. I also have nginx setup systemwide (not via docker) w/https via letsencrypt. I setup an A-record cloud.foo.com and setup the corresponding reverse proxy via nginx to point to localhost:8080.

This all seems to work fine for accessing via web, however the nextcloud instance still thinks it's domain / server name is 'localhost'. This is apparent by going to settings > Mobile & desktop where you see "server address: http://localhost:8080/". This also breaks functionality of all apps as when setup the server address as https://cloud.foo.com it loads a page asking to log in first or use an app token, both of which subsequently redirect to localhost:8080 which obviously are unreachable.

I am transitioning away from owncloud, and there they had a setting (OWNCLOUD_DOMAIN=cloud.foo.com) you added to your .env file that told OC what domain is should say it is. From what I've gathered I believe you can manually edit the config.php to set an "overwritehost" setting, though I'm not too sure how to do that with docker-compose. Any help would be greatly appreciated.

Activity

  1. jiveman commented on Aug 28, 2019

    @jiveman
    Author

    I figured out my issue, leaving some bread crumbs in case someone else finds this thread.

    First my docker-compose.yml

    version: '2'
    
    volumes:
      nextcloud:
      db:
    
    services:
      db:
        image: mariadb
        command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
        restart: always
        volumes:
          - db:/var/lib/mysql
        environment:
          - MYSQL_ROOT_PASSWORD=supersecretpasswordyoushoulddefinitelydefinitelychange
          - MYSQL_PASSWORD=supersecretpasswordyoushouldprobablychange
          - MYSQL_DATABASE=nextcloud
          - MYSQL_USER=nextcloud
    
      app:
        image: nextcloud
        ports:
          - 127.0.0.1:8080:80
        links:
          - db
        volumes:
          - nextcloud:/var/www/html
          - /var/www/html/config/config.php:/var/www/html/config/config.php
          #- /var/www/html/config/config.php:/var/www/html/config/CAN_INSTALL
        restart: always
    

    You'll notice the lines I've added from the example Nextcloud gives on their site is just a mapping to the config.php file. This makes it available on the local system for editing. The second link (commented out) is a special file nextcloud looks for to know if it can run the setup again. This is handy if you've already configured your system and don't want to purge everything and start over. Simply uncomment out that line and run:
    sudo docker-compose down && sudo docker-compose rm --force && sudo docker-compose pull && sudo docker-compose build --pull && sudo docker-compose up --force-recreate --build. You'll be asked to create an admin account and setup database connection info again. Once setup is complete the config.php will get re-written.

    You'll now have to recomment out the "CAN_INSTALL" line and stop the docker container. Let's edit a few lines in the configuration file config.php.

    'overwrite.cli.url' => 'https://cloud.mytld.comt',
    'overwritehost' => 'cloud.mytld.com',
    'overwriteprotocol' => 'https',
    

    This tells nextcloud your publicly accessible name is cloud.mytld.com or whatever you setup your domain to point to.

    I hope this helps.

  2. icasdri commented on Sep 27, 2019

    @icasdri

    Related: #819

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions