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; } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix