在容器中,同样要先更新一下debian的下载源
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
安装nginx,python,pip
安装 pip3 install uwsgi
以下两个文件是运行uwsgi必须的文件
uwsgi_param
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.ini
[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 说明运行成功
停止uwsgi服务命令:uwsgi --stop uwsgi.pid
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填入的接口网址
nginx + uwsgi + debian + django部署
原文:https://www.cnblogs.com/jimmyhe/p/11720504.html