I've tried to get my api working on ec2 to working with my django/drf backend and my nuxt frontend app. When I deploy the app my frontend is rendered and my backend admin works but I cannot login or access any data using frontend.
I'm trying to find documentation on this online but I'm not getting far. On the DRF official docs or nginx official docs I don't see any documentation that show's how to configure api on ec2.
My app runs locally fine but on ec2 doesn't serve my frontend for backend data communications.
Should these settings work or am I missing something?
update
I've both frontend and backend reachable on the ec2 url. I've checked logs and the only error I get is
nuxtServerInit undefined
After a little more investigating it seems the API_URI url does not work. What is the correct way to configure the api uri to work with a hosted nuxt app with docker/ec2?
config for nginx
upstream django {
ip_hash;
server 127.0.0.1:8000;
}
upstream nuxt {
ip_hash;
server 127.0.0.1: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 80;
server_name localhost;
}
docker_compose
version: '3.4'
services:
db:
restart: always
image: postgres
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
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
- rabbitmq
restart: on-failure
nuxt:
build:
context: ./frontend
env_file: .env
command: bash -c "npm install && npm run build && npm run start"
volumes:
- ./frontend:/app
ports:
- "3000:3000"
depends_on:
- django
- redis
volumes:
redisdata:
.env
DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
DJANGO_SECRET_KEY=mysecretkey
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
PGADMIN_DEFAULT_PASSWORD=password123
API_URI=http://64-644-225-61/api