1.首先解决依赖问题:
Nginx编译需要的主要的东西 zlib, pcre, openssl都可以源码安装, nginx编译过程 中会让你指定pcre和zlib的目录 指在解压过后的目录就可 期间会出找不到文件 需 将依赖包编译一下 ./configure make make install
2.安装anaconda3(python) 和 virtualenv(可选)
3.配置django (不多阐述)app, static, urls, views等 可正常运行即可
4.django根目录新建一个xml或者ini文件用于uwsgi和nginx通信 (manage.py同级目录)例xml:
<uwsgi>
<socket>ip:port</socket> //内部端口 自定义 和nginx相同即可
<chdir>xxx/xxx</chdir> //项目路径
<module>xxx.wsgi</module> //协议 (django-admin startproject xxx) xxx:项目名
<processes>4</processes> // 进程数
<daemonize>uwsgi.log</daemonize> //日志文件
</uwsgi>
5.安装nginx(源码, 方便找路径)./configure (回步骤1) make make install
6.配置nginx 编译好之后应该在/usr/local/nginx/nginx.conf (有权限)或者自己在configure 指定的 路径(–prefix=xxx/xxx)(防止意外 备份一份nginx.conf) 清空配置文件 例:
worker_processes 1;
events {
worker_connections 1024; //默认是1024
}
http {
include mime.types
default_type application/octet-stream;
sendfile on;
server {
listen 8080//可更改 服务端口
server_name www.xxx.xxx //没感觉有啥用,有直接用这个连接的,亲测不行
Charset utf-8;
Location / {
Include uwsgi_params;
Uwsgi_pass ip:port //需和4中socket相同 通信
Uwsgi_param UWSGI_SCRIPT xxx.wsgi //xxx为项目名
Uwsgi_param UWSGI_CHDIR xxx/xxx //项目路径
}
}
}
7.启动nginx测试
执行 nginx -t 是否出错 没有错继续
8. pip install uwsgi (没有网找一个内网源, 或者源码) 执行uwsgi 如果有错误
chdir(): No such file or directory [core/uwsgi.c ling...
查看xml或者ini 配置问题
执行uwsgi 直接出异常 找不到文件.so还是.o记不太清
Which uwsgi 找到uwsgi目录
ldd这个目录 看是否有not found 有的话 which出来加环境
9.启动项目
xml所在路径 uwsgi -x xxx.xml 或者 uwsgi --ini xxx.ini
查看该目录下日志是否有异常
*** no app loaded. going in full dynamic mode *** 需解决
python版本如果不对也需要解决(可能没有依赖或者版本不同)
root用户/usr/local/nginx/sbin 下./nginx 启动 //./nginx -s reload ./nginx -s stop
(多次使用可能会出现被占用 pkill -9 nginx/ pkill -9 uwsgi)
非root 用户找到自己指定的目录同上操作
打开网址输入ip:port(ip服务器ip, port nginx的listen)