NGINX Configuration for multiple apps on the same server (changing ports)

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 20.0.7
Operating system and version (eg, Ubuntu 20.04): Raspberry OS
Apache or nginx version (eg, Apache 2.4.25): nginx
PHP version (eg, 7.4): 7.3

The issue I am facing:

I have an Raspberry Pi 4 Homeserver and i am running some applications on it as docker images. For example nextcloud and bitwarden.

In my current configuration I am using an extra swag container as reverse proxy along with every server application, redirecting the ports (446, 448 …) to the internal server port 443 of the docker stack.

Now I think running several swag instances for every application is not the best option and running just one instance for all applications should be as it was meant to be.

My question is, if I am running nextcloud as subfolder how can I change the port it listens to to 448? Does I have to set the upstream port in the proxy conf from 443 to 448? When using subdomain I think I only have to change the server listen port, but as subfolder I am not sure…

For example the subdomain config:

server {
listen 443 ssl;
listen [::]:443 ssl;

server_name nextcloud.*;

include /config/nginx/ssl.conf;

client_max_body_size 0;

location / {
    include /config/nginx/proxy.conf;
    resolver 127.0.0.11 valid=30s;
    set $upstream_app nextcloud;
    set $upstream_port 443;
    set $upstream_proto https;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    proxy_max_temp_file_size 2048m;
}
}

I think here would I just have to change the server listen port.

But what does I have to change in the subfolder config?

# Redirects for DAV clients
location = /.well-known/carddav {
return 301 $scheme://$host/nextcloud/remote.php/dav;
}

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

location /nextcloud {
return 301 $scheme://$host/nextcloud/;
}

location ^~ /nextcloud/ {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
set $upstream_app nextcloud;
set $upstream_port 443;
set $upstream_proto https;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;

rewrite /nextcloud(.*) $1 break;
#   proxy_max_temp_file_size 2048m;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
proxy_redirect off;
proxy_ssl_session_reuse off;
}