配置文件
#URL隐藏index.php location / { if (!-e request\_filename) { rewrite ^(.\*) /index.php?s=/$1 last; } } #允许txt文件访问 location ~ \.(txt|json)$ { root /home/www/; }
1编译自己的Nginx
Nginx官网
下载
解压
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如何通过连接池处理网络请求