一、下载
(1) 官网地址:http://nginx.org/en/download.html
可以选择版本下载,本案例中选择下载红色区域的Linux Nginx版本
二、准备
1、将压缩包上传到Linux服务器上;
2、解压: tar -zxvf xxxx.tar.gz;
3、进入解压之后的目录,执行 ./configure (切记:nginx的解压目录不要作为安装目录,否则安装会失败,提示文件重复)
以上error部分就表示先决条件缺失:未安装PCRE,若按照 6 执行,会出现其显示的问题
5、此时文件夹中多处 makeFile文件
6、执行 make
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
出现的问题:
(1)
表示缺少编译Nginx的先决条件
Nginx是C语言开发,建议在linux上运行
1)gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc
需要执行的命令:yum install gcc-c++
2)PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
需要执行的命令:yum install -y pcre pcre-devel
3)zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
需要运行的命令:yum install -y zlib zlib-devel
4)openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
需要运行的命令:yum install -y openssl openssl-devel
(2) 在公司内网无法通过 yum命令安装以上基本组件怎么办?
A) 安装 zlib
- 查看安装版本
#find /usr/ -name zlib.pc
/usr/lib64/pkgconfig/zlib.pc
#cat /usr/lib64/pkgconfig/zlib.pc
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib64
sharedlibdir=${libdir}
includedir=/usr/include
Name: zlib
Description: zlib compression library
Version: 1.2.3
Requires:
Libs: -L$ {libdir} -L$ {sharedlibdir} -lz
Cflags: -I${includedir}
————————————————
版权声明:本文为CSDN博主「Huxiaoxiao_Linux」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Huxiaoxiao_Linux/java/article/details/89400893
若通过以上命令查不到版本,表示未安装,此时按下面流程进行安装
- 下载源:http://www.zlib.net/
- 解压:tar -zxvf zlib-1.2.11.tar.gz
- 重命名 :mv zlib-1.2.11 zlib
- 配置、编译、安装:
cd zlib
[root@HikvisionOS zlib]# ./configure && make && make install Checking for gcc... Checking for shared library support... Building shared library libz.so.1.2.11 with gcc. Checking for size_t... Yes. Checking for off64_t... Yes. Checking for fseeko... Yes. Checking for strerror... Yes. Checking for unistd.h... Yes. Checking for stdarg.h... Yes. Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf(). Checking for vsnprintf() in stdio.h... Yes. Checking for return value of vsnprintf()... Yes. Checking for attribute(visibility) support... Yes. gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o adler32.o adler32.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o crc32.o crc32.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o deflate.o deflate.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o infback.o infback.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o inffast.o inffast.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o inflate.o inflate.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o inftrees.o inftrees.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o trees.o trees.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o zutil.o zutil.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o compress.o compress.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o uncompr.o uncompr.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzclose.o gzclose.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzlib.o gzlib.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzread.o gzread.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzwrite.o gzwrite.c ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o example example.o -L. libz.a gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o minigzip.o test/minigzip.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzip minigzip.o -L. libz.a gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/adler32.o adler32.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/crc32.o crc32.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/deflate.o deflate.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/infback.o infback.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/inffast.o inffast.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/inflate.o inflate.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/inftrees.o inftrees.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/trees.o trees.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/zutil.o zutil.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/compress.o compress.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/uncompr.o uncompr.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzclose.o gzclose.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzlib.o gzlib.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzread.o gzread.c gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzwrite.o gzwrite.c gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o libz.so.1.2.11 adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo -lc rm -f libz.so libz.so.1 ln -s libz.so.1.2.11 libz.so ln -s libz.so.1.2.11 libz.so.1 gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o examplesh example.o -L. libz.so.1.2.11 gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzipsh minigzip.o -L. libz.so.1.2.11 gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -D_FILE_OFFSET_BITS=64 -c -o example64.o test/example.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o example64 example64.o -L. libz.a gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -D_FILE_OFFSET_BITS=64 -c -o minigzip64.o test/minigzip.c gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzip64 minigzip64.o -L. libz.a rm -f /usr/local/lib/libz.a cp libz.a /usr/local/lib chmod 644 /usr/local/lib/libz.a cp libz.so.1.2.11 /usr/local/lib chmod 755 /usr/local/lib/libz.so.1.2.11 rm -f /usr/local/share/man/man3/zlib.3 cp zlib.3 /usr/local/share/man/man3 chmod 644 /usr/local/share/man/man3/zlib.3 rm -f /usr/local/lib/pkgconfig/zlib.pc cp zlib.pc /usr/local/lib/pkgconfig chmod 644 /usr/local/lib/pkgconfig/zlib.pc rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h cp zlib.h zconf.h /usr/local/include chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
- 添加到系统配置
创建文件,命令:vim /etc/ld.so.conf.d/zlib.conf
填入内容(为zlib的安装路径):/opt/tianmu/zlib
- 加载配置,执行命令:ldconfig
遇到的问题:
zlib:[root@HikvisionOS openssl-fips-2.0.16]# ldconfig ldconfig: /lib64/libXv.so.1 is not a symbolic link
可忽略,解决办法为
这个表示 libXv.so.1应该是一个符号链接,但却是一个实体。采用以下方式纠正:
[root@HikvisionOS lib64]# ls |grep libXv.so.1 libXv.so.1 libXv.so.1.0.0 [root@HikvisionOS lib64]# ln -sf libXv.so.1 libXv.so [root@HikvisionOS lib64]# ldconfig ldconfig: /lib64/libXv.so.1 is not a symbolic link [root@HikvisionOS lib64]# ls |grep libXv. libXv.so libXv.so.1 libXv.so.1.0.0 [root@HikvisionOS lib64]# rm -f libXv.so.1
B) 安装 PCRE
- 下载源码
https://sourceforge.net/projects/pcre/files/pcre/
- 上传Linux服务器进行编译
- 解压
- 重名名 :mv pcre-8.44 pcre
- 配置:进入 pcre目录,执行 ./configure --enable-utf8
[root@HikvisionOS pcre]# ./configure --enable-utf8 checking for a BSD-compatible install... /bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether make supports nested variables... (cached) yes checking whether make supports the include directive... yes (GNU style) checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking dependency style of gcc... gcc3 checking for ar... ar checking the archiver (ar) interface... ar checking for gcc... (cached) gcc checking whether we are using the GNU C compiler... (cached) yes checking whether gcc accepts -g... (cached) yes checking for gcc option to accept ISO C89... (cached) none needed checking whether gcc understands -c and -o together... (cached) yes checking dependency style of gcc... (cached) gcc3 checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking dependency style of g++... gcc3 checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for int64_t... yes checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking how to print strings... printf checking for a sed that does not truncate output... /bin/sed checking for fgrep... /bin/grep -F checking for ld used by gcc... /bin/ld checking if the linker (/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /bin/nm -B checking the name lister (/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for /bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... dlltool checking how to associate runtime and link libraries... printf %s checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /bin/nm -B output from gcc object... ok checking for sysroot... no checking for a working dd... /bin/dd checking how to truncate binary pipes... /bin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... no checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking how to run the C++ preprocessor... g++ -E checking for ld used by g++... /bin/ld -m elf_x86_64 checking if the linker (/bin/ld -m elf_x86_64) is GNU ld... yes checking whether the g++ linker (/bin/ld -m elf_x86_64) supports shared libraries... yes checking for g++ option to produce PIC... -fPIC -DPIC checking if g++ PIC flag -fPIC -DPIC works... yes checking if g++ static flag -static works... no checking if g++ supports -c -o file.o... yes checking if g++ supports -c -o file.o... (cached) yes checking whether the g++ linker (/bin/ld -m elf_x86_64) supports shared libraries... yes checking dynamic linker characteristics... (cached) GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether ln -s works... yes checking whether the -Werror option is usable... yes checking for simple visibility declarations... yes checking for ANSI C header files... (cached) yes checking limits.h usability... yes checking limits.h presence... yes checking for limits.h... yes checking for sys/types.h... (cached) yes checking for sys/stat.h... (cached) yes checking dirent.h usability... yes checking dirent.h presence... yes checking for dirent.h... yes checking windows.h usability... no checking windows.h presence... no checking for windows.h... no checking for alias support in the linker... no checking for alias support in the linker... no checking string usability... yes checking string presence... yes checking for string... yes checking bits/type_traits.h usability... no checking bits/type_traits.h presence... no checking for bits/type_traits.h... no checking type_traits.h usability... no checking type_traits.h presence... no checking for type_traits.h... no checking for strtoq... yes checking for long long... yes checking for unsigned long long... yes checking for an ANSI C-conforming const... yes checking for size_t... yes checking for bcopy... yes checking for memmove... yes checking for strerror... yes checking zlib.h usability... no checking zlib.h presence... no checking for zlib.h... no checking for gzopen in -lz... no checking bzlib.h usability... no checking bzlib.h presence... no checking for bzlib.h... no checking for libbz2... no checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating libpcre.pc config.status: creating libpcre16.pc config.status: creating libpcre32.pc config.status: creating libpcreposix.pc config.status: creating libpcrecpp.pc config.status: creating pcre-config config.status: creating pcre.h config.status: creating pcre_stringpiece.h config.status: creating pcrecpparg.h config.status: creating config.h config.status: executing depfiles commands config.status: executing libtool commands config.status: executing script-chmod commands config.status: executing delete-old-chartables commands pcre-8.44 configuration summary: Install prefix .................. : /usr/local C preprocessor .................. : gcc -E C compiler ...................... : gcc C++ preprocessor ................ : g++ -E C++ compiler .................... : g++ Linker .......................... : /bin/ld -m elf_x86_64 C preprocessor flags ............ : C compiler flags ................ : -g -O2 -fvisibility=hidden C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden Linker flags .................... : Extra libraries ................. : Build 8 bit pcre library ........ : yes Build 16 bit pcre library ....... : no Build 32 bit pcre library ....... : no Build C++ library ............... : yes Enable JIT compiling support .... : no Enable UTF-8/16/32 support ...... : no Unicode properties .............. : no Newline char/sequence ........... : lf R matches only ANYCRLF ......... : no EBCDIC coding ................... : no EBCDIC code for NL .............. : n/a Rebuild char tables ............. : no Use stack recursion ............. : yes POSIX mem threshold ............. : 10 Internal link size .............. : 2 Nested parentheses limit ........ : 250 Match limit ..................... : 10000000 Match limit recursion ........... : MATCH_LIMIT Build shared libs ............... : yes Build static libs ............... : yes Use JIT in pcregrep ............. : no Buffer size for pcregrep ........ : 20480 Link pcregrep with libz ......... : no Link pcregrep with libbz2 ....... : no Link pcretest with libedit ...... : no Link pcretest with libreadline .. : no Valgrind support ................ : no Code coverage ................... : no
- 编译:make
[root@HikvisionOS pcre]# make rm -f pcre_chartables.c ln -s ./pcre_chartables.c.dist pcre_chartables.c make all-am make[1]: Entering directory `/opt/tianmu/pcre' CC pcretest-pcretest.o CC pcretest-pcre_printint.o CC libpcre_la-pcre_byte_order.lo CC libpcre_la-pcre_compile.lo CC libpcre_la-pcre_config.lo CC libpcre_la-pcre_dfa_exec.lo CC libpcre_la-pcre_exec.lo CC libpcre_la-pcre_fullinfo.lo CC libpcre_la-pcre_get.lo CC libpcre_la-pcre_globals.lo CC libpcre_la-pcre_jit_compile.lo CC libpcre_la-pcre_maketables.lo CC libpcre_la-pcre_newline.lo CC libpcre_la-pcre_ord2utf8.lo CC libpcre_la-pcre_refcount.lo CC libpcre_la-pcre_string_utils.lo CC libpcre_la-pcre_study.lo CC libpcre_la-pcre_tables.lo CC libpcre_la-pcre_ucd.lo CC libpcre_la-pcre_valid_utf8.lo CC libpcre_la-pcre_version.lo CC libpcre_la-pcre_xclass.lo CC libpcre_la-pcre_chartables.lo CCLD libpcre.la CC libpcreposix_la-pcreposix.lo CCLD libpcreposix.la CCLD pcretest CC pcregrep-pcregrep.o CCLD pcregrep CXX pcrecpp_unittest-pcrecpp_unittest.o CXX libpcrecpp_la-pcrecpp.lo CXX libpcrecpp_la-pcre_scanner.lo CXX libpcrecpp_la-pcre_stringpiece.lo CXXLD libpcrecpp.la CXXLD pcrecpp_unittest CXX pcre_scanner_unittest-pcre_scanner_unittest.o CXXLD pcre_scanner_unittest CXX pcre_stringpiece_unittest-pcre_stringpiece_unittest.o CXXLD pcre_stringpiece_unittest make[1]: Leaving directory `/opt/tianmu/pcre'
- 编译完之后进行测试:编译完后可以执行make check进行测试(这一步非必须) : make check
[root@HikvisionOS pcre]# make check make check-am make[1]: Entering directory `/opt/tianmu/pcre' make make[2]: Entering directory `/opt/tianmu/pcre' make all-am make[3]: Entering directory `/opt/tianmu/pcre' make[3]: Leaving directory `/opt/tianmu/pcre' make[2]: Leaving directory `/opt/tianmu/pcre' make check-TESTS make[2]: Entering directory `/opt/tianmu/pcre' make[3]: Entering directory `/opt/tianmu/pcre' PASS: pcrecpp_unittest PASS: pcre_scanner_unittest PASS: pcre_stringpiece_unittest PASS: RunTest PASS: RunGrepTest ============================================================================ Testsuite summary for PCRE 8.44 ============================================================================ # TOTAL: 5 # PASS: 5 //表示成功 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ make[3]: Leaving directory `/opt/tianmu/pcre' make[2]: Leaving directory `/opt/tianmu/pcre' make[1]: Leaving directory `/opt/tianmu/pcre'
- 安装: make install
C) 安装 openSSL(建议直接安装在 /usr/local/openssl 下,本文由于未安装到该目录下,导致nginx始终报opensll未安装的问题,后面采用另外一种方式解决)
- 下载源:https://www.openssl.org/source/
- 检查是否安装:openssl version -a
- 上传包到 /opt/tianmu下
- 解压 openssl-fips-2.0.16.tar.gz当当前目录下 (该版本没有sll.sh)
- cd openssl-fips-2.0
- 配置、编译、安装
./config shared zlib --prefix=/opt/tianmu/openssl && make && make install
建议不要安装在解压的目录里面,否则会出现错误(若非要安装在解压的目录里面,可以将上面的--prefix 值修改为 /opt/tianmu/openssl/.openssl)
- ./config -tmake depend
[root@HikvisionOS openssl-fips-2.0.16]# ./config -tmake depend Operating system: x86_64-whatever-linux2 Auto Configuring fipsonly Auto Configuring fipsonly Configuring for linux-x86_64 /bin/perl ./Configure linux-x86_64 depend -Wa,--noexecstack no-bf no-camellia no-cast no-idea no-md2 no-md5 no-mdc2 no-rc2 no-rc4 no-rc5 no-ripemd no-seed
- 建立软链接
- 在/etc/ld.so.conf文件的最后面,添加如下内容:/opt/tianmu/openssl/lib
如图所示:
- 然后执行命令: ldconfig
- 最后一步: 添加OPESSL的环境变量,在etc/的profile的最后一行,添加如下内容:
export OPENSSL=/opt/tianmu/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
- 环境变量生效、
让/etc/profile文件修改后立即生效 ,可以使用如下命令:
# . /etc/profile
注意: . 和 /etc/profile 有空格
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7、make clean 清除 生成的makefile文件,在安装了以上先决条件库之后;
8、 执行 ./configure命令
[root@HikvisionOS nginx]# ./configure --prefix=/opt/tianmu/nginx --pid-path=/opt/tianmu/nginx/run --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-http_image_filter_module --with-debug checking for OS + Linux 3.10.0-957.5.1.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found checking for gcc builtin atomic operations ... found checking for C99 variadic macros ... found checking for gcc variadic macros ... found checking for gcc builtin 64 bit byteswap ... found checking for unistd.h ... found checking for inttypes.h ... found checking for limits.h ... found checking for sys/filio.h ... not found checking for sys/param.h ... found checking for sys/mount.h ... found checking for sys/statvfs.h ... found checking for crypt.h ... found checking for Linux specific features checking for epoll ... found checking for EPOLLRDHUP ... found checking for EPOLLEXCLUSIVE ... not found checking for O_PATH ... found checking for sendfile() ... found checking for sendfile64() ... found checking for sys/prctl.h ... found checking for prctl(PR_SET_DUMPABLE) ... found checking for prctl(PR_SET_KEEPCAPS) ... found checking for capabilities ... found checking for crypt_r() ... found checking for sys/vfs.h ... found checking for poll() ... found checking for /dev/poll ... not found checking for kqueue ... not found checking for crypt() ... not found checking for crypt() in libcrypt ... found checking for F_READAHEAD ... not found checking for posix_fadvise() ... found checking for O_DIRECT ... found checking for F_NOCACHE ... not found checking for directio() ... not found checking for statfs() ... found checking for statvfs() ... found checking for dlopen() ... not found checking for dlopen() in libdl ... found checking for sched_yield() ... found checking for sched_setaffinity() ... found checking for SO_SETFIB ... not found checking for SO_REUSEPORT ... found checking for SO_ACCEPTFILTER ... not found checking for SO_BINDANY ... not found checking for IP_TRANSPARENT ... found checking for IP_BINDANY ... not found checking for IP_BIND_ADDRESS_NO_PORT ... not found checking for IP_RECVDSTADDR ... not found checking for IP_SENDSRCADDR ... not found checking for IP_PKTINFO ... found checking for IPV6_RECVPKTINFO ... found checking for TCP_DEFER_ACCEPT ... found checking for TCP_KEEPIDLE ... found checking for TCP_FASTOPEN ... found checking for TCP_INFO ... found checking for accept4() ... found checking for eventfd() ... found checking for int size ... 4 bytes checking for long size ... 8 bytes checking for long long size ... 8 bytes checking for void * size ... 8 bytes checking for uint32_t ... found checking for uint64_t ... found checking for sig_atomic_t ... found checking for sig_atomic_t size ... 4 bytes checking for socklen_t ... found checking for in_addr_t ... found checking for in_port_t ... found checking for rlim_t ... found checking for uintptr_t ... uintptr_t found checking for system byte ordering ... little endian checking for size_t size ... 8 bytes checking for off_t size ... 8 bytes checking for time_t size ... 8 bytes checking for AF_INET6 ... found checking for setproctitle() ... not found checking for pread() ... found checking for pwrite() ... found checking for pwritev() ... found checking for sys_nerr ... found checking for localtime_r() ... found checking for clock_gettime(CLOCK_MONOTONIC) ... found checking for posix_memalign() ... found checking for memalign() ... found checking for mmap(MAP_ANON|MAP_SHARED) ... found checking for mmap("/dev/zero", MAP_SHARED) ... found checking for System V shared memory ... found checking for POSIX semaphores ... not found checking for POSIX semaphores in libpthread ... found checking for struct msghdr.msg_control ... found checking for ioctl(FIONBIO) ... found checking for ioctl(FIONREAD) ... found checking for struct tm.tm_gmtoff ... found checking for struct dirent.d_namlen ... not found checking for struct dirent.d_type ... found checking for sysconf(_SC_NPROCESSORS_ONLN) ... found checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found checking for openat(), fstatat() ... found checking for getaddrinfo() ... found checking for PCRE library ... found checking for PCRE JIT support ... found checking for OpenSSL library ... not found checking for OpenSSL library in /usr/local/ ... not found checking for OpenSSL library in /usr/pkg/ ... not found checking for OpenSSL library in /opt/local/ ... not found ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.
红色部分显示找不到openSSL 库,但实际上已经安装在了 /opt/tianmu/openssl 下 ,此时在配置命令里面 增加指令 --with-openssl=openssl解压目录,此时配置nginx的时候,openssl 会被自动安装,安装在openssl解压目录下的.openssl 目录下。 如果pcre和zlib出现类似的问题,指定路径就可。
--with-pcre=/usr/local/pcre-7.7 --with-zlib=/usr/local/zlib-1.2.3 --with-http_stub_status_module
root@HikvisionOS nginx]# ./configure --prefix=/opt/tianmu/nginx --pid-path=/opt/tianmu/nginx/run --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-debug --with-openssl=/opt/tianmu/openssl checking for OS + Linux 3.10.0-957.5.1.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found checking for gcc builtin atomic operations ... found checking for C99 variadic macros ... found checking for gcc variadic macros ... found checking for gcc builtin 64 bit byteswap ... found checking for unistd.h ... found checking for inttypes.h ... found checking for limits.h ... found checking for sys/filio.h ... not found checking for sys/param.h ... found checking for sys/mount.h ... found checking for sys/statvfs.h ... found checking for crypt.h ... found checking for Linux specific features checking for epoll ... found checking for EPOLLRDHUP ... found checking for EPOLLEXCLUSIVE ... not found checking for O_PATH ... found checking for sendfile() ... found checking for sendfile64() ... found checking for sys/prctl.h ... found checking for prctl(PR_SET_DUMPABLE) ... found checking for prctl(PR_SET_KEEPCAPS) ... found checking for capabilities ... found checking for crypt_r() ... found checking for sys/vfs.h ... found checking for poll() ... found checking for /dev/poll ... not found checking for kqueue ... not found checking for crypt() ... not found checking for crypt() in libcrypt ... found checking for F_READAHEAD ... not found checking for posix_fadvise() ... found checking for O_DIRECT ... found checking for F_NOCACHE ... not found checking for directio() ... not found checking for statfs() ... found checking for statvfs() ... found checking for dlopen() ... not found checking for dlopen() in libdl ... found checking for sched_yield() ... found checking for sched_setaffinity() ... found checking for SO_SETFIB ... not found checking for SO_REUSEPORT ... found checking for SO_ACCEPTFILTER ... not found checking for SO_BINDANY ... not found checking for IP_TRANSPARENT ... found checking for IP_BINDANY ... not found checking for IP_BIND_ADDRESS_NO_PORT ... not found checking for IP_RECVDSTADDR ... not found checking for IP_SENDSRCADDR ... not found checking for IP_PKTINFO ... found checking for IPV6_RECVPKTINFO ... found checking for TCP_DEFER_ACCEPT ... found checking for TCP_KEEPIDLE ... found checking for TCP_FASTOPEN ... found checking for TCP_INFO ... found checking for accept4() ... found checking for eventfd() ... found checking for int size ... 4 bytes checking for long size ... 8 bytes checking for long long size ... 8 bytes checking for void * size ... 8 bytes checking for uint32_t ... found checking for uint64_t ... found checking for sig_atomic_t ... found checking for sig_atomic_t size ... 4 bytes checking for socklen_t ... found checking for in_addr_t ... found checking for in_port_t ... found checking for rlim_t ... found checking for uintptr_t ... uintptr_t found checking for system byte ordering ... little endian checking for size_t size ... 8 bytes checking for off_t size ... 8 bytes checking for time_t size ... 8 bytes checking for AF_INET6 ... found checking for setproctitle() ... not found checking for pread() ... found checking for pwrite() ... found checking for pwritev() ... found checking for sys_nerr ... found checking for localtime_r() ... found checking for clock_gettime(CLOCK_MONOTONIC) ... found checking for posix_memalign() ... found checking for memalign() ... found checking for mmap(MAP_ANON|MAP_SHARED) ... found checking for mmap("/dev/zero", MAP_SHARED) ... found checking for System V shared memory ... found checking for POSIX semaphores ... not found checking for POSIX semaphores in libpthread ... found checking for struct msghdr.msg_control ... found checking for ioctl(FIONBIO) ... found checking for ioctl(FIONREAD) ... found checking for struct tm.tm_gmtoff ... found checking for struct dirent.d_namlen ... not found checking for struct dirent.d_type ... found checking for sysconf(_SC_NPROCESSORS_ONLN) ... found checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found checking for openat(), fstatat() ... found checking for getaddrinfo() ... found checking for PCRE library ... found checking for PCRE JIT support ... found checking for zlib library ... found creating objs/Makefile Configuration summary + using system PCRE library + using OpenSSL library: /opt/tianmu/openssl + using system zlib library nginx path prefix: "/opt/tianmu/nginx" nginx binary file: "/opt/tianmu/nginx/sbin/nginx" nginx modules path: "/opt/tianmu/nginx/modules" nginx configuration prefix: "/opt/tianmu/nginx/conf" nginx configuration file: "/opt/tianmu/nginx/conf/nginx.conf" nginx pid file: "/opt/tianmu/nginx/run" nginx error log file: "/opt/tianmu/nginx/logs/error.log" nginx http access log file: "/opt/tianmu/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
9、执行make命令
10、执行 make install 命令
出现了以下错误,此时可以检查下 下载的openssl中有没有ssl.sh,本文中下载的无,所以重新下载了 openssl-1.1.1e.tar.gz 版本
In file included from src/core/ngx_core.h:84:0, from src/core/nginx.c:9: src/event/ngx_event_openssl.h:15:25: fatal error: openssl/ssl.h: No such file or directory #include <openssl/ssl.h> ^ compilation terminated. make[1]: *** [objs/src/core/nginx.o] Error 1 make[1]: Leaving directory `/opt/tianmu/nginx' make: *** [build] Error 2
也有可能出现以下错误(是由于执行./configure命令时,--prefix 的值配成了解压的路径,导致文件冲突)
[root@HikvisionOS nginx]# make install make -f objs/Makefile install make[1]: Entering directory `/opt/tianmu/nginx' test -d '/opt/tianmu/nginx' || mkdir -p '/opt/tianmu/nginx' test -d '/opt/tianmu/nginx/sbin' || mkdir -p '/opt/tianmu/nginx/sbin' test ! -f '/opt/tianmu/nginx/sbin/nginx' || mv '/opt/tianmu/nginx/sbin/nginx' '/opt/tianmu/nginx/sbin/nginx.old' cp objs/nginx '/opt/tianmu/nginx/sbin/nginx' test -d '/opt/tianmu/nginx/conf' || mkdir -p '/opt/tianmu/nginx/conf' cp conf/koi-win '/opt/tianmu/nginx/conf' cp: ‘conf/koi-win’ and ‘/opt/tianmu/nginx/conf/koi-win’ are the same file make[1]: *** [install] Error 1 make[1]: Leaving directory `/opt/tianmu/nginx' make: *** [install] Error 2
此时需要 执行 make clean 移除MakeFile文件,重新执行一遍 ./configure 、 make 、make install 命令
11、启动nginx
有可能出现上述黑框问题,其表示
没有安装nginx用户导致的无法启动
1
2
|
[root@localhost nginx-1.11.2] # useradd -s /sbin/nologin -M nginx [root@localhost nginx-1.11.2] # id nginx |
最后,可以在服务器上命令 curl 服务器地址+nginx端口号
![](https://upload-images.jianshu.io/upload_images/14298675-154189b73d248027.png)
![](https://img2020.cnblogs.com/blog/604780/202004/604780-20200402211821089-2021877504.png)
或者,浏览器上输入你的 服务器地址 + nginx端口
![](https://upload-images.jianshu.io/upload_images/14298675-5483dc31c0f86dde.png)