在容器中,一样要先更新一下debian的下载源python
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
安装nginx,python,pipnginx
安装 pip3 install uwsgiweb
如下两个文件是运行uwsgi必须的文件docker
uwsgi_paramdjango
uwsgi_param QUERY_STRING $query_string; uwsgi_param REQUEST_METHOD $request_method; uwsgi_param CONTENT_TYPE $content_type; uwsgi_param CONTENT_LENGTH $content_length; uwsgi_param REQUEST_URI $request_uri; uwsgi_param PATH_INFO $document_uri; uwsgi_param DOCUMENT_ROOT $document_root; uwsgi_param SERVER_PROTOCOL $server_protocol; uwsgi_param REQUEST_SCHEME $scheme; uwsgi_param HTTPS $https if_not_empty; uwsgi_param REMOTE_ADDR $remote_addr; uwsgi_param REMOTE_PORT $remote_port; uwsgi_param SERVER_PORT $server_port; uwsgi_param SERVER_NAME $server_name;
uwsgi.inibash
[uwsgi] socket = 127.0.0.1:50000 chdir = /home/httpServer/ # 能够理解为此文件的绝对路径 wsgi-file = httpServer/wsgi.py # wsgi与chdir的相对路径 processes = 4 daemonize = /home/log/httpServer.log // 日志 pidfile = /tmp/uwsgi.pid master = True
用uwsgi代替wsgi运行django网络
uwsgi --ini uwsgi.ini // 写uwsgi.ini相对路径便可负载均衡
出现:[uWSGI] getting INI configuration from uwsgi.ini 说明运行成功dom
中止uwsgi服务命令:uwsgi --stop uwsgi.pidsocket
apt-get nginx, 下载nginx ,输入nginx便可启动
关于nginx不能启动 ==》 在bash栏里输入nginx 根据提示修改配置文件
你们能够查看一下 /etc/nginx/nginx.conf 相关信息,第61,62行有两个include,分别是引入配置和生效文件的,咱们等会本身配置的文件就要软链接(至关于快捷方式引入)到62行的位置里。因此
/etc/nginx/sites-enabled/ 里的全部文件都是你编辑后生效的,尽可能不要有重复的,可能会覆盖不起做用
编写本身项目的nginx转发:
upstream django { // 配置好被转发到哪一个端口 # server unix:///home/abc/uwsgi-tutorial/mysite/mysite.sock; # for a file socket server 0.0.0.0:3032; # for a web port socket (we'll use this first) } server { # the port your site will be served on listen 8002; // nginx负责监听的端口 # the domain name it will serve for server_name localhost; # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; // 转发的路由 include /root/sxx_system/uwsgi_params; } }
注意:nginx转发,先要启动uwsgi,在uwsgi_pass中传入uwsgi填入的接口网址