nginx

文章目录

初始Nginx

编译自己的Nginx

编译安装
# 下载nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz
# 解压
tar zxvf nginx-1.16.1.tar.gz
# 进入解压后的nginx文件夹
cd nginx-1.16.1
# 把contrib中的vim拷贝到自己的vim中用于高亮显示nginx配置语法
cp -r contrib/vim/* ~/.vim
# 查看man下的nginx帮助文档
man ./man/nginx.8
# 查看 configure 支持哪些参数
./configure --help | more
# 指定安装目录
./configure --prefix=/usr/local/nginx
# 编译
make
# 安装
make install
编译安装shell脚本
#!/usr/bin/env bash

nginx_install()
{
   
  # 安装依赖
  yum -y install pcre-devel zlib-devel
  # 下载nginx
  wget http://nginx.org/download/nginx-1.16.1.tar.gz
  # 解压
  tar zxvf nginx-1.16.1.tar.gz
  # 进入解压后的nginx文件夹
  cd nginx-1.16.1
  # 指定安装目录
  ./configure --prefix=/usr/local/nginx
  # 编译
  make
  # 安装
  make install
}

echo "开始安装nginx"
nginx_install
echo "结束安装nginx"

编译异常
# make时异常
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
# 安装pcre-devel
yum -y install pcre-devel
# make时异常
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
# 安装zlib-devel
yum install -y zlib-devel

Nginx命令行

  • 格式 : nginx -s reload
  • 帮助 : -? -h
  • 使用指定的配置文件 : -c
  • 指定配置指令 : -g
  • 指定运行目录 : -p
  • 发送信号 : -s
    • 立刻停止服务 : stop
    • 优雅的停止服务 : quit
    • 重载配置文件 : reload
    • 重新开始记录日志文件 : reopen
  • 测试配置文件是否有语法错误 : -t -T
  • 打印nginx版本信息、编译信息等 : -v -V

Nginx热部署

# 复制老的nginx二进制文件
cp nginx nginx.old
# 将编译的新版本nginx二进制文件覆盖nginx二进制文件

# 查看nginx进程id
ps -ef | grep nginx
root      8794     1  0 22:47 ?        00:00:00 nginx: master process ./nginx
nobody    8795  8794  0 22:47 ?        00:00:00 nginx: worker process

# 给老的nginx进程发送热部署信号
kill -USR2 8794
# 查看nginx进程信息
ps -ef | grep nginx
root      8794     1  0 22:47 ?        00:00:00 nginx: master process ./nginx
nobody    8795  8794  0 22:47 ?        00:00:00 nginx: worker process
root     13490  8794  0 22:55 ?        00:00:00 nginx: master process ./nginx
nobody   13491 13490  0 22:55 ?        00:00:00 nginx: worker process
root     13493  2766  0 22:56 pts/0    00:00:00 grep --color=auto nginx
# 给老的nginx优雅关闭work进程
kill -WINCH 8794
# 查看nginx进程信息
ps -ef | grep nginx
root      8794     1  0 22:47 ?        00:00:00 nginx: master process ./nginx
root     13490  8794  0 22:55 ?        00:00:00 nginx: master process ./nginx
nobody   13491 13490  0 22:55 ?        00:00:00 nginx: worker process
root     13502  2766  0 22:58 pts/0    00:00:00 grep --color=auto nginx

Nginx 日志切割

nginx -s reopen
# 或者
kill -USR1 $(cat /usr/local/openresty/nginx/logs/nginx.pid)

:<<BLOCK
1、在没有执行kill -USR1 `cat ${
     pid_path}`之前,即便已经对文件执行了mv命令也只是改变了文件的名称,nginx还是会向新命名的文件” access.log.20161024”中照常写入日志数据。原因在于linux系统中,内核是根据文件描述符来找文件的

2、USR1是自定义信号,也就是进程编写者自己确定收到这个信号该干什么。而在nginx中它自己编写了代码当接到USR1信号的时候让nginx重新打开日志文件(重新打开的日志就是配置文件中设置的位置和名称)
BLOCK

goaccess

# 安装
yum install -y goaccess
# 执行命令
# access.log 是要分析的日志文件
# -o 输出的分析静态文件
# /var/www/html/report.html 是输出分析文件地址
# --real-time-html 实时跟新
# --time-format goaccess 与日志文件对应的格式
goaccess access.log -o report.html --real-time-html --time-format='%H:%M:%
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值