Nginx核心知识100讲笔记

​小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

配置文件

URL隐藏index.php

location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}

允许txt文件访问

location ~ \.(txt|json)$ {
root /home/www/;
}

1编译自己的Nginx

Nginx官网

http://nginx.org/en/download.html

下载

wget http://nginx.org/download/nginx-1.18.0.tar.gz

解压

tar -xzf nginx-1.18.0.tar.gz

预编译

cd nginx-1.18.0

查看文件目录

ll

拷贝contrib文件

cp -r contrib/vim/* ~/.vim/

查看configure支持哪些命令

./configure --help | more

指定Nginx安装目录, 配置 nginx

./configure --prefix=/usr/local/nginx

可能有报错
错误为:./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
yum -y install pcre-devel

还有可能出现:

错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.



解决办法:

yum -y install openssl openssl-devel

make编译nginx(生成2进制)

make

安装nginx(把生成的 2 进制复制到 prefix 指定的安装路径里)

make install

重启nginx重启服务

cd /usr/local/nginx/sbin

./nginx -s reload

报错
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
解决办法
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

---------------------

nginx热部署

( 在不打断用户请求的情况下更新版本 切换版本,只更新二进制文件)

记录目录

cd /usr/local/nginx/sbin

查看命令

ps -ef | grep nginx

[root@VM-0-8-centos sbin]# ps -ef | grep nginx
root     16664     1  0 10:59 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   16671 16664  0 10:59 ?        00:00:00 nginx: worker process
root     17329  1435  0 11:04 pts/0    00:00:00 grep --color=auto nginx

cp nginx nginx.old

ll

kill -USR2 13195

ps -ef | grep nginx

旧的平滑到新的

kill -WINCH 13195

ps -ef | grep nginx (无worker进程了,旧的master还在以做版本恢复)

日志切割

cd /usr/local/nginx/logs

mv error.log bakerror.log

../sbin/nginx -s reopen

ll

crontab -l

rotate.sh进行自动备份

------------------------

查看nginx进程

ps -ef | grep nginx

kill -SIGTERM 16980

三次握手

33 | Nginx的模块究竟是什么?

34 | Nginx模块的分类

35 | Nginx如何通过连接池处理网络请求

Buy me a cup of coffee :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值