在容器中,一樣要先更新一下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填入的接口網址