Redirect error when installing nextcloud with nginx

Steps I followed:

install arch linux arm v8 on raspberry pi 3 model b as per instructions at
https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3

set up netctl profile via connected keyboard and monitor

ssh into raspberry pi

su

pacman -Syu

pacman -S sudo

pacman -S vim

vim /etc/sudoers (uncomment line that allows wheel to sudo w/out password)

exit

sudo netctl enable [profile_name]

sudo pacman -S nginx php postgresql php-gd php-intl php-pgsql nextcloud

create file /etc/pacman.d/hooks/nextcloud.hook

# Update Nextcloud when core or -apps are touched
 
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = nextcloud
Target = nextcloud-app-*
 
[Action]
Description = Updating Nextcloud installation
When = PostTransaction
Exec = /usr/bin/runuser -u http -- /usr/bin/php /usr/share/webapps/nextcloud/occ upgrade

sudo vim /etc/php/php.ini (uncomment extensions gd iconv pdo_pgsql pgsql bz2 intl

su

mount /dev/sda1 /mnt #the external hard drive

cd /mnt

mkdir nextcloud

cd nextcloud

mkdir apps apps2 data

su -l postgres

initdb --locale $LANG -E UTF8 -D ‘/var/lib/postgres/data’

exit

systemctl start postgresql

systemctl enable postgresql

su -l postgres

createuser -h localhost -P nextcloud

createdb -O nextcloud nextcloud

exit

exit

sudo mkdir /etc/nginx/conf.d/

In /etc/nginx/nginx.conf, add the following lines under the “http” section:

http {
...
...
server_names_hash_bucket_size 64;
include conf.d/*.conf;
}

create /etc/nginx/conf.d/nextcloud.conf as shown at
https://docs.nextcloud.com/server/13/admin_manual/installation/nginx.html

upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    listen [::]:80;
    server_name cloud.example.com;
    # enforce https
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name cloud.example.com;

    ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
    ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;

    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this
    # topic first.
    # add_header Strict-Transport-Security "max-age=15768000;
    # includeSubDomains; preload;";
    #
    # WARNING: Only add the preload option once you read about
    # the consequences in https://hstspreload.org/. This option
    # will add the domain to a hardcoded list that is shipped
    # in all major browsers and getting removed from this list
    # could take several months.
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

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

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

    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
    # last;

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

    # 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/vnd.ms-fontobject 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;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    location / {
        rewrite ^ /index.php$uri;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        deny all;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        #Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri/ =404;
        index index.php;
    }

    # Adding the cache control header for js and css files
    # Make sure it is BELOW the PHP block
    location ~ \.(?:css|js|woff|svg|gif)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=15778463";
        # Add headers to serve security related headers (It is intended to
        # have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into
        # this topic first.
        # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
        #
        # WARNING: Only add the preload option once you read about
        # the consequences in https://hstspreload.org/. This option
        # will add the domain to a hardcoded list that is shipped
        # in all major browsers and getting removed from this list
        # could take several months.
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        # Optional: Don't log access to assets
        access_log off;
    }

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        # Optional: Don't log access to other assets
        access_log off;
    }
}

change the php-handler block in /etc/nginx/conf.d/nextcloud.conf so it looks
like this one:

upstream php-handler {
   server unix:/run/php-fpm/php-fpm.sock;
}

Uncomment env[PATH] = /usr/local/bin:/usr/bin:/bin in /etc/php/php-fpm.d/www.conf

in /etc/nginx/conf.d/nextcloud.conf:
change root to /usr/share/webapps/nextcloud
change server_name to 192.168.1.227
change ssl lines to:

ssl_certificate /etc/nginx/ssl/fake_cert.crt;
ssl_certificate_key /etc/nginx/ssl/fake_cert.key;

sudo mkdir /etc/nginx/ssl

cd /etc/nginx/ssl

sudo openssl req -new -x509 -nodes -newkey rsa:4096 -keyout fake_cert.key -out fake_cert.crt -days 1095

sudo chmod 400 fake_cert.key

sudo chmod 444 fake_cert.crt

sudo systemctl start nginx php-fpm

view 192.168.1.227 in browser -> can’t write to apps dir error

change /usr/share/nextcloud/config/config.php to:

<?php
$CONFIG = array (
  'instanceid' => 'oc8ay35v1sfr',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/mnt/nextcloud/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/mnt/nextcloud/apps2',
      'url' => '/apps2',
      'writable' => true,
    ),
  ),
  'datadirectory' => '/mnt/nextcloud/data'
);

sudo systemctl restart nginx php-fpm

view 192.168.1.227 in browser -> locales error

uncomment en_US utf8 line in /etc/locale.gen

sudo locale-gen

sudo systemctl restart nginx php-fpm

view 192.168.1.227 in browser

input admin password

input database user “nextcloud” with password created for that user when first
running createuser and database name “nextcloud” and ip “localhost”.

-> page loads for a while and then displays

The page isn’t redirecting properly

An error occurred during a connection to 192.168.1.227.

This problem can sometimes be caused by disabling or refusing to accept cookies.

try to log in on nextcloud for android -> “Malformed server configuration”

All config files I changed:

/usr/share/webapps/nextcloud/config/config.php:

https://pastebin.com/CXfCjhDx

/etc/nginx/conf.d/nextcloud.conf:

https://pastebin.com/A69CPQwv

/etc/nginx/nginx.conf:

https://pastebin.com/fXhhX3ej

/etc/php/php-fpm.d/www.conf

https://pastebin.com/Bc9e2XF7

/etc/php/php.ini

https://pastebin.com/bX7YfNhD

For all other errors, I have been able to get some clue as to what is going on and debug them, but this is giving me no real feedback, so I felt like I needed to go somewhere for help. Hopefully someone here can find an error in my configuration, or at least how to view some useful logs in this situation. If you have any further questions about the situation, please ask me.