To run two separate Docker apps with different domains on the same Ubuntu server, you'll need to modify your docker-compose.yml
and nginx.conf
files accordingly. Here's a guide on how to achieve this:
- Create two separate folders for each app, let's say
app1
andapp2
. Place your Nuxt.js and Strapi apps for each domain in their respective folders. - Modify the
docker-compose.yml
file for each app. Update thenginx
service to expose different ports, for example,8080
forapp1
and8081
forapp2
. You should also give each app a unique network name, e.g.,app1_network
andapp2_network
. Here's an example forapp1
:
version: '3'
services:
nginx:
build: ./nginx
ports:
- "8080:80"
depends_on:
- backend
- frontend
networks:
- app1_network
# ... other services ...
networks:
app1_network:
driver: bridge
- Modify the
nginx.conf
file in thenginx
folder of each app to set the correctserver_name
. For example, forapp1
, setserver_name nsd.newtablab.com;
, and forapp2
, setserver_name www.newstablab.com;
. - Install Nginx on your Ubuntu server, if it's not already installed:
sudo apt update
sudo apt install nginx
- Create a new Nginx configuration file
/etc/nginx/sites-available/reverse-proxy.conf
with the following content:
http {
upstream app1 {
server localhost:8080;
}
upstream app2 {
server localhost:8081;
}
server {
listen 80;
server_name nsd.newtablab.com;
location / {
proxy_pass http://app1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name www.newstablab.com;
location / {
proxy_pass http://app2;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
- Create a symbolic link to enable the configuration:
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/
- Remove the
default
configuration:
sudo rm /etc/nginx/sites-enabled/default
- Restart Nginx:
sudo systemctl restart nginx
- Start both Docker apps by running
docker-compose up -d
in their respective directories (app1
andapp2
).
Now, your Nuxt.js and Strapi apps should be accessible at nsd.newtablab.com
and www.newstablab.com
.