Dockerized nginx and django on Apache installed VPS
I'm trying to deploy my dockerized django project with nginx container to a VPS server which has apache. Nginx conf with 80 port, I'm getting port already in use error. Therefore, I've changed my config as following.
nginx.conf;
server {
listen 8080;
server_name sub.example.com;
resolver 127.0.0.11 ipv6=off valid=10s;
charset utf-8;
location /static {
alias /var/www/static;
}
location / {
proxy_pass http://app;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
docker-compose.yml;
version: '3.8'
services:
nginx:
restart: unless-stopped
build:
context: ./nginx
dockerfile: './Dockerfile'
ports:
- "8080:8080"
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
- staticfiles:/var/www/static
container_name: nginx
depends_on:
- app
app:
image: core
build: ./
restart: always
container_name: app
command: bash -c "python manage.py collectstatic --noinput && python manage.py migrate && gunicorn --bind 0.0.0.0:8000 core.wsgi:application --reload"
volumes:
- ./storage/assets/staticfiles:/app/storage/assets/staticfiles
- staticfiles:/app/storage/assets/staticfiles/
- .:/app
expose:
- 8000
ports:
- 8000:8000
env_file:
- .env
depends_on:
- redis
redis:
restart: always
image: redis:latest
expose:
- "6379"
worker:
build: ./
command: celery -A core worker -l info -Q celery
environment:
- C_FORCE_ROOT=true
volumes:
- .:/app
depends_on:
- redis
beat:
build: ./
command: celery -A core beat -l info
volumes:
- .:/app
links:
- redis
depends_on:
- redis
volumes:
staticfiles:
When I build and run the project on VPS server with the commands below, there is no error.
sudo docker build -t core:latest .
sudo docker run -d -p 8000:8080 core:latest
When I check the images with docker images, I can see my image. However, when I check the running containers by running docker ps, I cannot see my container and my subdomain redirects me to the main domain.
Could you please help me with this?