Docker-部署uwsgi服务代替django自带的服务器
发布日期:2021-05-10 11:26:55 浏览次数:20 分类:精选文章

本文共 3634 字,大约阅读时间需要 12 分钟。

���Docker���������������������Python3 + uWSGI + Nginx���Django���������

���������������Django���������������������������������Django���������web������������������python manage.py runserver������������������������������������������������������������Nginx + uWSGI������������������������������������������������������������������������������Django���������������unaugmented���������������������������������������


������������������������������

���������������������������������������������������

  • Python3���������������CentOS������������������Python2���������������Docker������������������Python3���������������������
  • Django���������������������������������������������������������������������������������������������������������������������

  • ������Python3���������������Docker���������

    1.������Python3���������������

    docker pull python:3.6

    2.������Python3������

    docker run -itd -v /project:/opt --rm --name python3env python:3.6
    • -v /project:/opt���������������������������������������������/opt������������
    • -itd������������������������interactive mode���������������������������������
    • --name python3env������������������������������������������

    ���������������������������������������������������������

    docker exec -it python3env bash

    3.������Django������������������

    ���������������������������������

    pip install django-guardian mysqlclient jira PyYAML

    ������Django������������

    1. ���������������������

    ���������������settings.py���������

    DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'mysql',
    'USER': 'root',
    'PASSWORD': '123456789',
    'HOST': '192.168.63.128',
    'PORT': '3306',
    }
    }

    2. ������������������������

    ���settings.py������������������������

    CORS_ALLOW_CREDENTIALS = True
    CORS_ORIGIN_ALLOW_ALL = True
    CORS_ORIGIN_WHITELIST = ()
    CORS_ALLOW_METHODS = (
    'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'VIEW'
    )
    CORS_ALLOW_HEADERS = (
    'accept', 'accept-encoding', 'authorization', 'content-type', 'dnt', 'origin',
    'user-agent', 'x-csrftoken', 'x-requested-with'
    )

    uWSGI���������������

    1. ������uWSGI

    ���������������������������

    pip install uwsgi -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

    2. ������uWSGI������������

    ���������������������������uwsgi.ini���������������������������������

    [uwsgi]
    wsgi.chdir = ./autotpsite.wsgi:application
    http=0.0.0.0:8081
    master=true
    pidfile=./uwsgi8081.pid
    daemonize=./uwsgi_server.log
    socket-timeout=10

    3. ������uWSGI

    ���������������������

    uwsgi uwsgi.ini

    Nginx���uWSGI���������������������

    1. ������������IP

    ���������������������������������������������

    ip addr

    ������������������������bridge������������������Docker���docker0���������

    2. ������������������IP

    docker network inspect bridge

    3. ������Nginx������������

    ���������������conf������������������default.conf���������������������������

    location / {
    proxy_pass http://192.168.63.128:3306;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    ������������������

    ������������������������

  • ���������������������Django���������������������
  • python manage.py runserver
    1. ������������������������������������

    2. ������������

      ������������������������������Docker���������������������uWSGI������Django������������������������������������Nginx������������������������������������������������

    3. ������Nginx������������������������uWSGI������������������
    4. ������Python���������IP������������������
    5. ������������������������������������������������������������������������Django���������������������

    上一篇:Docker和虚拟机之间的通信过程
    下一篇:Django中的路由分发

    发表评论

    最新留言

    路过,博主的博客真漂亮。。
    [***.116.15.85]2025年04月27日 13时33分34秒