使用Nginx部署Vue.js和Django API(DRF)

时间:2020-11-06 13:11:28

标签: django vue.js nginx docker-compose uwsgi

我正在尝试使用Nginx和uwsgi部署Vue应用程序和Django REST api。我在Nginx中设置反向代理以将发送到mysite.com/api的所有流量路由到Django应用程序时遇到问题。尝试访问api时出现404错误,并且也无法访问Django管理站点。这是我的docker-compose文件和Nginx配置。

version: "3"

services:
  web:
    stdin_open: true
    tty: true
    build:
      context: .
    volumes:
      - ./app:/app
    command: bash -c "
      python manage.py makemigrations
      && python manage.py migrate
      && uwsgi --socket :8000 --master --enable-threads --module settings.wsgi"
    environment:
      - DB_HOST=db
      - DB_NAME=app
      - DB_USER=postgres
      - DB_PASS=supersecretpassword
    depends_on:
      - db
    restart: on-failure

  db:
    image: postgis/postgis
    environment:
      - POSTGRES_DB=app
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=supersecretpassword
    restart: on-failure

  proxy:
    build:
      context: ./nginx
    ports:
      - "80:80"
    depends_on:
      - web

volumes:
  static_data:

这是Nginx的配置文件:

server {
    listen 80;

    location / {
        root /usr/share/nginx/html;
        try_files $uri /index.html;
    }

    location ^~ /api/ {
        uwsgi_pass web:8000;
        include /etc/nginx/uwsgi_params;
    }
}

0 个答案:

没有答案