nginx开启缓存

开启缓存添加内容如下:

内容来源:TCH. 赵

1
2
3
4
5
6
7
location ~.*\.(gif|jpg|png|css|js)(.*){
# proxy_cache cache_zone;
proxy_cache_valid 200 302 24h;
proxy_cache_valid any 50m;
expires 1d;
add_header X-Proxy-Cache $upstream_cache_status;
}

结果

报错

1
2
3
[root@localhost conf]# nginx -t
nginx: [emerg] using regex ".*\.(gif|jpg|png|css|js)(.*)" requires PCRE library in /opt/nginx/conf/nginx.conf:82
nginx: configuration file /opt/nginx/conf/nginx.conf test failed

原因分析:

安装的nginx包为最基础版本,没有封装PCRE包,不能使用正在表达式

参考链接:

https://www.jianshu.com/p/14c81fbcb401

https://www.cnblogs.com/crxis/p/6973232.html

nginx较完整版安装

参考链接:

nginx–如何基于rpm包进行离线安装及配置(Linux)
https://blog.csdn.net/JustinQin/article/details/119319705

安装包下载地址:

http://nginx.org/packages/

linux忽略依赖强制安装软件

https://blog.csdn.net/qq_41520220/article/details/126360495

安装命令:

http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.22.1-1.el7.ngx.x86_64.rpm

1
rpm -ivh nginx-1.22.1-1.el7.ngx.x86_64.rpm --nodeps --force 

其中: --nodeps --force 为rpm强制安装命令

启动遇到的问题

1
2
3
4
5
6
7
[root@localhost usr]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@localhost usr]# systemctl staus nginx
Unknown operation staus.
[root@localhost usr]# nginx -t
nginx: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory

网络上解决方案一:

https://blog.csdn.net/weixin_40720406/article/details/106526746

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost sbin]# pwd
/usr/sbin
[root@localhost sbin]# ldd $(which /usr/sbin/nginx)
linux-vdso.so.1 (0x00007ffcf15a5000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb82bc6c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb82ba4c000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fb82b823000)
libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007fb82b59f000)
libssl.so.10 => not found
libcrypto.so.10 => not found
libz.so.1 => /lib64/libz.so.1 (0x00007fb82b388000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb82afc5000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb82c1de000)

查找文件 libssl.so.10 所在位置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost lib64]# find / -name libdl.so.2
/usr/lib64/libdl.so.2
[root@localhost lib64]# cd /usr/lib64/
[root@localhost lib64]# find ./ -name libdl.so.2
./libdl.so.2
[root@localhost lib64]# find ./ -name '*libssl*'
./libssl3.so
./.libssl.so.1.1.1c.hmac
./.libssl.so.1.1.hmac
./libssl.so.1.1
./libssl.so.1.1.1c
[root@localhost lib64]# find ./ -name '*libcrypto*'
./.libcrypto.so.1.1.1c.hmac
./.libcrypto.so.1.1.hmac
./libcrypto.so.1.1
./libcrypto.so.1.1.1c

没有此文件,并且openssl可以正常查看

1
2
3
4
[root@localhost sbin]# openssl version
OpenSSL 1.1.1c FIPS 28 May 2019
[root@localhost sbin]# ssh -V
OpenSSH_8.0p1, OpenSSL 1.1.1c FIPS 28 May 2019

原因分析:

OpenSSL 1.1.1c 中没有文件 libssl.so.10 。nginx版本与openssl版本不适配,重装OpenSSL到版本为1.0.2

重装ssl

参考链接:

https://blog.csdn.net/qq_41661056/article/details/90485997

安装包下载链接:
http://rpmfind.net/linux/centos/7.9.2009/updates/x86_64/Packages/openssl-libs-1.0.2k-26.el7_9.x86_64.rpm

安装命令

1
rpm -ivh openssl-libs-1.0.2k-24.el7_9.x86_64.rpm --nodeps --force

最终现象:

可以找到两个原本没有的文件

重装nginx

卸载nginx

1
rpm -e nginx

安装nginx

1
rpm -ivh nginx-1.22.1-1.el7.ngx.x86_64.rpm 

启动nginx

1
systemctl start nginx

查看nginx的运行状态

1
systemctl status nginx

nginx开启缓存
http://yuanql.top/2023/03/22/29_nginx/nginx开启缓存/
作者
Qingli Yuan
发布于
2023年3月22日
许可协议