Two Angular apps on the same VPS?

1. Caddy version (caddy version):

caddy:2.4.6-alpine and caddy:2.4.5-alpine

2. How I run Caddy:

with docker compose (see below):

a. System environment:

Using Docker (compose)

b. Command:

docker-compose -f docker-compose.yml up -d

c. Service/unit/compose file:

version: "3.7"

services:

  vendingdb:
    image: mysql:latest
    container_name: vendingdb
    volumes:
      - vending_db:/var/lib/mysql
    ports:
      - 3307:3307
    environment:
      MYSQL_ROOT_HOST: '%'
      MYSQL_ROOT_USER: example
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: vendingdb

  vending-app:
    build:
      context: ./
      dockerfile: Dockerfile
    ports:
      - 8082:8082
    depends_on:
      - vendingdb
    environment:
      - SPRING_PROFILES_ACTIVE=prod

  vending-ui:
    build: ../frontend
    container_name: frontend_vending
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

volumes:
  caddy_data:
  caddy_config:
  vending_db:

d. My complete Caddyfile or JSON config:

vast.rest {
	header {
		Strict-Transport-Security max-age=31536000;
	}

	encode zstd gzip

	handle /api/* {
		reverse_proxy vending-app:8082
	}

	handle {
		root * /srv
		try_files {path} index.html
		file_server
	}
}

3. The problem I’m having:

I have a single VPS with two DNS connected to it. I’m already running another instance of mysql (port 3306) + java spring (port 8080) + angular (exposing 80 and 443) and connecting it with Caddy to one of the DNS instances with some test app, which works fine.
Now I’m wondering - is it it even possible to have two “front end” apps running on the same VPS?

4. Error messages and/or full log output:

5. What I already tried:

I’ve changed the ports for mysql and spring, but what about the ones for angular (80/443)? I am not even sure if this is Caddy’s work or not…

6. Links to relevant resources:

Yes, absolutely. Just make another site block in your config that handles the routes for the other app:

first.example.com {
	...
}

second.example.com {
	...
}

Make sure the Caddy container can proxy to the other app, make sure they share a docker network. You can create a docker network externally that you can add both Caddy and the other app to.

You would need to use a different directory for the two apps in Caddy though, for example /srv/first and /srv/second, so that they’re not overlapping volumes in the Caddy container.

Replying before the topic is auto closed, been busy with aws certification lately, but almost done with it and I’ll edit this/add a new comment in the next week (hopefully) with a response if the suggestions worked and what exactly changed in my configurations and docker.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.

This topic was automatically closed after 13 days. New replies are no longer allowed.