写在前面
本章常用指令
查看防火墙的88端口是否打开:firewall-cmd --list-port
开启88端口:firewall-cmd --zone=public --add-port=88/tcp --permanent
重启防火墙:firewall-cmd --reload
创建虚拟环境:mkvirtualenv testenv
进入虚拟环境:workon testenv
退出虚拟环境:deactivate
删除虚拟环境:rmvirtualenv testenv
nginx目录:cd /usr/local/nginx/sbin
查看nginx版本:./nginx -v
查看nginx状态:ps -ef|grep nginx
关闭:sudo ./nginx -s quit
测试:sudo ./nginx -t -c /root/yh/testdjango/text.conf
启动:sudo ./nginx -c /root/yh/testdjango/text.conf
uwsgi启动:uwsgi --ini /root/yh/testdjango/uwsgi.ini
重启:uwsgi --reload xxx.pid
停止:uwsgi --stop xxx.pid
查看状态:ps -ef|grep uwsgi
查看端口情况:lsof -i:8001
杀掉被占用端口:kill -9 进程pid
1、准备
windows端:
找到项目根目录
在templates下新建index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<h1>这是标题 1</h1>
<h2>这是标题 2</h2>
<h3>这是标题 3</h3>
<h4>这是标题 4</h4>
<h5>这是标题 5</h5>
<h6>这是标题 6</h6>
</body>
</html>
新建test.conf、uwsgi.ini
test.conf
user root;
worker_processes 1;
error_log /root/yh/testdjango/error.log warn;
pid /root/yh/testdjango/nginx.pid;
events {
worker_connections 1024;
}
http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 89;
server_name localhost;
root /root/yh/testdjango;
location /templates {
alias /root/yh/testdjango/templates;
}
location / {
include /usr/local/nginx/conf/uwsgi_params;
uwsgi_pass 127.0.0.1:8889;
}
}
}
uwsgi.ini
[uwsgi]
# nginx连接时
socket=0.0.0.0:8889
# 作为web服务器连接时
#http=0.0.0.0:8889
# 项目目录
chdir=/root/yh/testdjango
# wsgi目录(相对路径)
wsgi-file=testdjango/wsgi.py
# 进程
processes=4
# 每个进程里的线程
threads=10
# 是否开启多线程模式
enable-threads=True
# 是否开启接口
master=True
# 进程id存储文件
pidfile=uwsgi.pid
# 日志
daemonize=uwsgi.log
新建文件夹logs,里面新建error.log、nginx.pid两个空文件
在pycharm里面生成项目依赖文件:pip freeze > 1.txt
最终目录包含文件
压缩整个项目文件夹,上传到服务器(这里我是centos系统):rz
解压到/root/yh/testdjango:unzip -d /root/yh/testdjango 1.zip
2、服务器
开放防火墙端口:89、8889
新建虚拟环境:virtualenv -p /usr/local/bin/python3 /root/yh/testenv
生成虚拟环境:mkvirtualenv testenv
安装项目依赖:pip install -r 1.txt
启动nginx:
启动uwsgi:
到windows浏览器访问:这里没指定编码格式,但是你可以看到成功访问了