启动 nginx 时报错:error while loading
启动 nginx 时报错:error while loading shared libraries:
Nginx 启动出错 error while loading shared libraries: libpcre.so.1
error while loading shared libraries: libpcre.so.1
启动 nginx 时报错:
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
查看依赖库
ldd $(which /usr/local/nginx/sbin/nginx)
linux-vdso.so.1 (0x00007ffff1599000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe954f5b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe954d3c000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fe954b04000)
libluajit-5.1.so.2 => /usr/local/lib/libluajit-5.1.so.2 (0x00007fe954894000)
libpcre.so.1 => not found
libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fe95462a000)
libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fe9541b2000)
libz.so.1 => /usr/local/lib/libz.so.1 (0x00007fe953f94000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe953ba3000) /lib64/ld-linux-x86-64.so.2 (0x00007fe9554b0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe953805000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe9535ed000)
猜测可能有以下 3 种原因:
未安装 PCRE
libpcre.so.1 名字不对
未设置 LD_LIBRARY_PATH
安装 PCRE,不用多说。安装完之后仍出现以上报错呢。?
find / -name libpcre.so.1
发现找不到 libpcre.so.1 怎么办
到 /usr/local/lib 目录下查看
ls -l libpcre.so*lrwxrwxrwx 1 root root 17 7月 4 09:06 libpcre.so -> libpcre.so.1.2.10-rwxr-xr-x 1 root root 508296 7月 4 09:06 libpcre.so.1.2.10
发现原来是名字不对,遂设置软连接
ln -s /usr/local/lib/libpcre.so.1.2.10 libpcre.so.1
设置完软连接重启 nginx 发现仍然无法解决问题。
设置 LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
查看依赖库
ldd $(which /usr/local/nginx/sbin/nginx)
linux-vdso.so.1 (0x00007ffda9323000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f01627f9000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f01625da000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f01623a2000)
libluajit-5.1.so.2 => /usr/local/lib/libluajit-5.1.so.2 (0x00007f0162132000)
libpcre.so.1 => /usr/local/lib/libpcre.so.1 (0x00007f0161f14000)
libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f0161caa000)
libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f0161832000)
libz.so.1 => /usr/local/lib/libz.so.1 (0x00007f0161614000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0161223000) /lib64/ld-linux-x86-64.so.2 (0x00007f0162d4e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0160e85000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0160c6d000)
最终,问题解决。