【发布时间】:2020-06-08 23:11:05
【问题描述】:
我有一个 dockerized 应用程序,它在我的主机上的开发模式下运行良好。我试图弄清楚如何使用启动实例时创建的默认 IP 地址在 ec2 上托管我的应用程序。
我的文件夹结构如下。
backend
|---projectname
|---Dockerfile
|---requirements.txt
|---wait-for-it.sh
config/nginx
|---app.conf
frontend
|---nuxt folders
|---Dockerfile
这是我当前正在使用的 docker compose 文件
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;
}
如果我的 ec2 域名指针是 ec2-52-204-122-132.compute-1.amazonaws.com 如何在我的应用中设置 nginx 以接受与我的应用前端的 http 连接?
在后端 localhost:8000/admin 是我的管理页面,我也想使用 ec2 域名访问它。
更改配置的最佳方法是什么,以便在添加域名指针后推送我的应用程序时,我可以访问托管在 ec2 上的应用程序?
我一直在阅读文档,但找不到任何有关在 ec2 上运行的 dockerized django vue 类型应用程序的有用信息。
【问题讨论】:
标签: django docker nginx amazon-ec2