使用nginx、uwsgi、daphne、supervisor 部署django channels项目

需要的环境,python3、mysql、redis、nginx
python 的web服务器 :uwsgi、daphne
需要的python包
django mysqlclient channels channels_redis

远程到服务器

shell >>> ssh root@ip
Password : 12345678

系统

lrwxrwxrwx.   1 root root    7 4月  24 03:54 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 4月  24 04:01 boot
drwxr-xr-x.  21 root root 3200 4月  24 03:58 dev
drwxr-xr-x.  75 root root 8192 4月  24 04:37 etc
drwxr-xr-x.   2 root root    6 4月  11 2018 home
lrwxrwxrwx.   1 root root    7 4月  24 03:54 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 4月  24 03:54 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4月  11 2018 media
drwxr-xr-x.   2 root root    6 4月  11 2018 mnt
drwxr-xr-x.   2 root root    6 4月  11 2018 opt
dr-xr-xr-x. 134 root root    0 4月  24 03:58 proc
dr-xr-x---.   2 root root  151 4月  24 04:49 root
drwxr-xr-x.  26 root root  760 4月  24 04:40 run
lrwxrwxrwx.   1 root root    8 4月  24 03:54 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 4月  24 03:58 sys
drwxrwxrwt.   9 root root  288 4月  24 04:56 tmp
drwxr-xr-x.  13 root root  155 4月  24 03:54 usr
drwxr-xr-x.  20 root root  278 4月  24 04:37 var

我把压缩包全部放在了/var/opt 文件夹下
所以先

shell >>> cd /var/opt

一、安装nginx
nginx文档 http://nginx.org/en/docs/
来源博客:
https://www.cnblogs.com/liujuncm5/p/6713784.html
https://www.cnblogs.com/zhanghaoyong/p/7737536.html

1、安装环境

1)安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install gcc-c++
2)PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。
yum install -y pcre pcre-devel
3)zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
yum install -y zlib zlib-devel
4)OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yum install openssl

2、安装nginx
可以直接去官网下载(网址:https://nginx.org/en/download.html)

1)下载
yum install wget	安装下载器(如果有可以不安装)
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz		下载tar包
tar -zxvf nginx-1.12.0.tar.gz			解压
2)安装
cd nginx-1.12.0		进入解压后的目录
./configure			使用默认配置		可以自定义配置 命令:./configure \	(不推荐)
make & make install		编译安装
3) 查看安装路径
whereis nginx		--->  nginx: /usr/local/nginx

3、启动、停止nginx

cd /usr/local/nginx/sbin/
./nginx		启动
./nginx -s stop		此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s quit		此方式停止步骤是待nginx进程处理任务完毕进行停止。
ps aux|grep nginx	查询nginx进程
./nginx -s reload	当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效
./nginx -t			测试配置文件是否正常

使用时可能会报错

[root@localhost sbin]# ./nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

解决: 命令:   
shell >>> /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

[root@localhost sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@localhost sbin]# ./nginx -s reload
[root@localhost sbin]# 

启动时报错

[root@localhost sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

端口被占用,应该是我之前安装了apache

nginx 的配置文件在 /usr/local/nginx/conf/nginx.conf

4、修改端口

shell >>> vim 
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 26
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值