Nextcloud app on iPhone authentication issue outside of Network

First time poster,

I have my Nextcloud working on Ubuntu Server 16.04.1 LTS and am able to login locally on my local network and devices locally. I have my home router port forwarding setup to allow access to my Nextcloud Internal IP address.

I’ve installed the Nextcloud app on my iPhone 6 and am able to sign in locally but can’t connect externally. “Error it is not possible to connect to the server at this time. Request failed: gateway timed out (504)”

I’ve verified my Netcloud server has access on port 80 and 443 (nothing else is using those ports on my network). My plex and subsonic apps are working remotely.

Now since this is my first time setting this up, here is my step by step I documented. Maybe there is something in these steps I messed up on? or something else I need to configure to allow the Nextcloud app to connect back to my home server outside of my network?


Installing NextCloud on Ubuntu 16.04

Step 1: Login in Root
(create root admin, disable when done)
sudo passwd root
sudo passwd -u root
(login)
su -
password:

Step 2: Update the System:

sudo apt-get update # Fetches the list of available updates
sudo apt-get upgrade # Strictly upgrades the current packages
sudo apt-get dist-upgrade # Installs updates (new ones)

Step 3: Install LAMP Server + PHP Extension:

sudo apt-get install lamp-server^
enter in password for root user
sudo apt-get install libapache2-mod-php7.0 php7.0-mbstring php7.0-curl php7.0-zip php7.0-gd php7.0-mysql php7.0-mcrypt
sudo apt-get install php-xml

Step 4: Download NextCloud:

wget wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip

Step 5: Unzip + Permissions:

unzip nextcloud-11.0.1.zip
sudo mv nextcloud /var/www/html
sudo chown -R www-data:www-data /var/www/html/nextcloud

Step 6: Configuring MariaDB for NextCloud:

mysql_secure_installation
Type n, n ,y for all except root password
mysql -u root -p
In SQL do the following;

CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO ‘nextcloud’@‘localhost’ IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;
exit;

Step 7: Disable MariaDB binary logging:

sudo vi /etc/mysql/my.cnf

Add the following three lines at the end:

log-bin = /var/log/mysql/mariadb-bin
log-bin-index = /var/log/mysql/mariadb-bin.index
binlog_format = mixed

Step 8: Configuring Apache Web Server:

sudo a2enmod rewrite
sudo touch /etc/apache2/sites-available/nextcloud.conf
sudo ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf
sudo vi /etc/apache2/sites-available/nextcloud.conf

service apache2 restart

Add the following:

<VirtualHost *:443>
DocumentRoot "/var/www/html/nextcloud/"
ServerName example.com <-change this
ServerAlias nextcloud
<Directory “/var/www/html/nextcloud/”>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

ErrorLog /var/log/apache2/your-domain.com-error_log
CustomLog /var/log/apache2/your-domain.com-access_log common

Restart the Apache web server:

sudo systemctl restart apache2.service

Open in web browser

http://localip/nextcloud

I found this in the Admin Manual - https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html

Could this be the problem?


Trusted Domains

All URLs used to access your Nextcloud server must be whitelisted in your config.php file, under the trusted_domains setting. Users are allowed to log into Nextcloud only when they point their browsers to a URL that is listed in the trusted_domains setting. You may use IP addresses and domain names. A typical configuration looks like this:

‘trusted_domains’ =>
array (
0 => ‘localhost’,
1 => ‘server1.example.com’,
2 => ‘192.168.1.50’,
),

Are you sure you setup port forwarding correctly? Would you be able to give me you external or domain name for troubleshooting?

I found the issue, I forgot to run the following on my Nextcloud Server setup;

a2enmod ssl
a2ensite default-ssl

I’m able to login now through my iPhone Nextcloud app remotely to my Nextcloud server.