Nginx安装

下载Nginx

安装Nginx

# 安装Nginx依赖
dnf install pcre-devel openssl openssl-devel
# 安装Nginx扩展模块
git clone https://github.com/vozlt/nginx-module-vts.git
wget  http://nginx.org/download/nginx-1.20.2.tar.gz
tar zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
# 设备Nginx配置
./configure --with-openssl=/usr/local/openssl --prefix=/usr/local/software/nginx --conf-path=/usr/local/software/nginx/conf/nginx.conf --error-log-path=/usr/local/software/nginx/logs/error.log --http-log-path=/usr/local/software/nginx/logs/access.log --http-client-body-temp-path=/usr/local/software/nginx/tmp/client_body --http-proxy-temp-path=/usr/local/software/nginx/tmp/proxy --http-fastcgi-temp-path=/usr/local/software/nginx/tmp/fastcgi --without-http_uwsgi_module --without-http_scgi_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-cc-opt='-O2 -g' --add-module=../nginx-module-vts --with-http_v2_module
# 编译安装
make && make install
# 创建nginx相关文件夹
mkdir /usr/local/software/nginx/tmp
mkdir /usr/local/software/nginx/logs

可能出现的问题

/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/usr/local/src/nginx-1.9.9’
make: *** [build] Error 2
需要说明的是,我这里编译所使用的Nginx源码是1.9.9的。根据报错信息我们知道,出错是因为Nginx在编译时并不能在/usr/local/ssl/.openssl/ 这个目录找到对应的文件,其实我们打开/usr/local/ssl/这个目录可以发现这个目录下是没有.openssl目录的,因此我们修改Nginx编译时对openssl的路径选择就可以解决这个问题了
解决方案:
打开nginx源文件下的/usr/local/src/nginx-1.9.9/auto/lib/openssl/conf文件:
找到这么一段代码:
CORE_INCS=“$CORE_INCS O P E N S S L / . o p e n s s l / i n c l u d e " C O R E D E P S = " OPENSSL/.openssl/include" CORE_DEPS="OPENSSL/.openssl/include"COREDEPS="CORE_DEPS O P E N S S L / . o p e n s s l / i n c l u d e / o p e n s s l / s s l . h " C O R E L I B S = " OPENSSL/.openssl/include/openssl/ssl.h" CORE_LIBS="OPENSSL/.openssl/include/openssl/ssl.h"CORELIBS="CORE_LIBS O P E N S S L / . o p e n s s l / l i b / l i b s s l . a " C O R E L I B S = " OPENSSL/.openssl/lib/libssl.a" CORE_LIBS="OPENSSL/.openssl/lib/libssl.a"CORELIBS="CORE_LIBS O P E N S S L / . o p e n s s l / l i b / l i b c r y p t o . a " C O R E L I B S = " OPENSSL/.openssl/lib/libcrypto.a" CORE_LIBS="OPENSSL/.openssl/lib/libcrypto.a"CORELIBS="CORE_LIBS N G X L I B D L " 修改成以下代码: C O R E I N C S = " NGX_LIBDL" 修改成以下代码: CORE_INCS="NGXLIBDL"修改成以下代码:COREINCS="CORE_INCS O P E N S S L / i n c l u d e " C O R E D E P S = " OPENSSL/include" CORE_DEPS="OPENSSL/include"COREDEPS="CORE_DEPS O P E N S S L / i n c l u d e / o p e n s s l / s s l . h " C O R E L I B S = " OPENSSL/include/openssl/ssl.h" CORE_LIBS="OPENSSL/include/openssl/ssl.h"CORELIBS="CORE_LIBS O P E N S S L / l i b / l i b s s l . a " C O R E L I B S = " OPENSSL/lib/libssl.a" CORE_LIBS="OPENSSL/lib/libssl.a"CORELIBS="CORE_LIBS O P E N S S L / l i b / l i b c r y p t o . a " C O R E L I B S = " OPENSSL/lib/libcrypto.a" CORE_LIBS="OPENSSL/lib/libcrypto.a"CORELIBS="CORE_LIBS $NGX_LIBDL”

生成service文件

vi /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/software/nginx/sbin/nginx
ExecReload=/usr/local/software/nginx/sbin/nginx -s reload
ExecStop=/usr/local/software/nginx/sbin/nginx -s quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

设置Nginx开机启动和相关操作命令

# 开机启动
 systemctl daemon-reload
 systemctl enable nginx
# 操作命令
 systemctl start nginx
 systemctl stop nginx
 systemctl reload nginx

版权声明:本文为weixin_44715918原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。