python docker部署 nginx代理并发送到uwsgi
Dockerfile(生成容器的脚本文件)
FROM centos/python-36-centos7 MAINTAINER sam USER root WORKDIR /home # 下载pip包 RUN pip install uwsgi -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com COPY requirements.txt /home/requirements.txt # 使用淘宝的npm镜像 RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com RUN pip install -r requirements.txt #ENTRYPOINT [ "/bin/bash", "/home/entry-point.sh"] #ENTRYPOINT uwsgi --ini /home/hello.ini #CMD ["uwsgi","--ini", "/home/hello.ini"] #启动uwsgi
生成容器(注意后面有一个点)
sudo docker build -t mquwsgi .
进入容器
docker exec -it mquwsgi bash
entry-point.sh(docker运行时启动这个脚本)
if [ -e /debug1 ]; then echo "Running app in debug mode!" python /home/mqsub.ini else echo "Running app in production mode!"uwsgi --ini /home/mqsub.ini int.sh tail -f /home/mqsub.ini fi
mqsub.ini(通过:wsgi-file=app.py 正式启动软件)
[uwsgi] # htmlWeb.py文件所在目录 #plugins = python3 chdir = /home callable = app # flask文件名 wsgi-file= app.py # 进程数 processes = 1 # 使用5000端口 http = 0.0.0.0:5000 # 日志输出目录 daemonize = /home/mqsub.log pidfile = /home/project-master.pid
nginx代理python网站的配置文件(nginx.conf)
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; server { listen 80; server_name www.xiaoyan.link; #charset koi8-r; #access_log logs/host.access.log main; location / { # proxy_pass http://127.0.0.1:5000; proxy_pass http://121.43.147.156:5000; #nginx和python都在独立容器中,ip地址不同,不能用(127.0.0.1) proxy_redirect off; proxy_set_header Host $http_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; } } }

浙公网安备 33010602011771号