0
点赞
收藏
分享

微信扫一扫

Nginx核心知识100讲笔记

at小涛 2022-02-10 阅读 75


配置文件

#URL隐藏index.php

location / {

if (!-e request\_filename) { rewrite ^(.\*) /index.php?s=/$1 last;

}

}

#允许txt文件访问

location ~ \.(txt|json)$ {

root /home/www/;

}

1编译自己的Nginx

Nginx官网

​​nginx.org/en/download…​​

下载

wget ​​nginx.org/download/ng…​​

解压

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还在以做版本恢复)

Nginx核心知识100讲笔记_php

日志切割

cd /usr/local/nginx/logs

mv error.log bakerror.log

../sbin/nginx -s reopen

ll

crontab -l

Nginx核心知识100讲笔记_nginx_02

rotate.sh进行自动备份

Nginx核心知识100讲笔记_php_03

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

Nginx核心知识100讲笔记_Nginx_04

Nginx核心知识100讲笔记_nginx_05

Nginx核心知识100讲笔记_进制_06

Nginx核心知识100讲笔记_php_07

Nginx核心知识100讲笔记_php_08

Nginx核心知识100讲笔记_Nginx_09

查看nginx进程

ps -ef | grep nginx

kill -SIGTERM 16980

Nginx核心知识100讲笔记_Nginx_10

Nginx核心知识100讲笔记_Nginx_11

Nginx核心知识100讲笔记_Nginx_12

Nginx核心知识100讲笔记_php_13

三次握手

Nginx核心知识100讲笔记_Nginx_14

Nginx核心知识100讲笔记_进制_15

Nginx核心知识100讲笔记_Nginx_16

Nginx核心知识100讲笔记_nginx_17

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

Nginx核心知识100讲笔记_nginx_18

Nginx核心知识100讲笔记_Nginx_19

34 | Nginx模块的分类

Nginx核心知识100讲笔记_进制_20

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

Nginx核心知识100讲笔记_php_21

Nginx核心知识100讲笔记_nginx_22

Nginx核心知识100讲笔记_进制_23

Buy me a cup of coffee :)



举报

相关推荐

0 条评论