Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29253

Nginix configuration for django nuxt app with docker hosted on ec2

$
0
0

I have a dockerized app that works fine in development mode on my host machine. I'm trying to figure out how I can host my app on ec2 using the default ip address created when I launch my instance.

My folder structure is as follows.

backend
|---projectname
|---Dockerfile
|---requirements.txt 
|---wait-for-it.sh

config/nginx
|---app.conf

frontend
|---nuxt folders 
|---Dockerfile

This is my current docker compose file I'm using

docker-compose.yml

version: '3.4'

services:
db:
    restart: always
    image: postgres
    volumes:
    - pgdata:/var/lib/postgresql/data  
    env_file: .env

    ports:
    - "5432:5432"
    expose:
    - 5432  

redis:
    restart: always
    image: redis
    volumes:
    - redisdata:/data


django:
    build:
    context: ./backend
    env_file: .env

    command: >
    sh -c  "./wait-for-it.sh db:5432 && 
            cd autobets && python manage.py collectstatic --noinput &&
            gunicorn --workers=2 --bind=0.0.0.0:8000 autobets.wsgi:application" 
    ports:
    - "8000:8000"
    volumes:
    - ./backend:/app
    depends_on:
    - db
    restart: on-failure


nuxt:
    build:
    context: ./frontend
    environment:
    - API_URI=http://django:8000/api

    command: bash -c "npm install && npm run dev"
    volumes:
    - ./frontend:/app
    ports:
    - "3000:3000"
    depends_on:
    - django
    - redis

volumes:
  pgdata:
  redisdata:

config/nginx/app.config

upstream django {
ip_hash;
server django:8000;
}

upstream nuxt {
ip_hash;
server nuxt:3000;
}

server {
location ~ /(api|admin|static)/ {
    proxy_pass http://django;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $host;
}
location / {
    proxy_pass http://nuxt;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $host;
}
listen 8000;
server_name localhost;
}

Say if my ec2 domain name pointer is ec2-52-204-122-132.compute-1.amazonaws.com How do I set nginx up in my app to accept http connections to the frontend of my app?

On the backend localhost:8000/admin is my admin page I'd like to access this also using the ec2 domain name too.

What's the best way to alter my config so when I push my app after add the domain name pointer I can access my app hosted on ec2?

I've been reading documentation but can't find any helpful info for a dockerized django vue type app running on ec2.


Viewing all articles
Browse latest Browse all 29253

Trending Articles