linux安装nginx&增加ssl

安装nginx

1.安装nginx

cd /opt
wget https://nginx.org/download/nginx-1.21.2.tar.gz
tar -zxvf nginx-1.21.2.tar.gz

2.cd 至解压后的目录,运行./configure 进行初始化配置;

cd ./nginx-1.21.2   # 进入解压目录
./configure   # 运行./configure

如果出现以下情况,则需要安装依赖包

如果未出现以下情况,执行步骤3

# 提示 error: the HTTP rewrite module requires the PCRE library.
$ yum install -y pcre pcre-devel
# 提示 error: Invalid C++ compiler or C++ compiler flags.
$ yum install -y gcc gcc-c++
# 提示 error: the HTTP gzip module requires the zlib library.
$ yum install -y zlib-devel
# 提示 error: SSL modules require the OpenSSL library.
$ yum -y install openssl openssl-devel

依赖包安装完后,返回 nginx 解压目录,再次运行 ./configure 进行初始化即可

$ cd /home/nginx-1.21.2   # 返回 nginx 解压目录
$ ./configure   # 再次运行./configure

3.执行编译

make

4.执行安装

make install

5.运行nginx

$ whereis nginx   # 查找安装路径
nginx: /usr/local/nginx   # 返回路径
$ cd /usr/local/nginx   # 进入安装路径
$ ./sbin/nginx   # 运行

6.查看是否运行成功

ps -ef | grep nginx

11.nginx增加SSL模块

1.查看nginx原有的模块

/usr/local/nginx/sbin/nginx -V

2.在configure arguments:后面显示的原有的configure参数如下:

configure arguments: 

3.切换到源码包

cd /opt/nginx-1.21.1

4.编译ssl模块

./configure --with-http_ssl_module

5.配置

make

注意:这里不要进行make install,否则就是覆盖安装

6.备份nginx

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

7.停止nginx

ps -ef | grep nginx
kill -quit pid

8.覆盖nginx

cp ./objs/nginx /usr/local/nginx/sbin/

9.测试

cd /usr/local/
./sbin/nginx

查看安装模块

/usr/local/nginx/sbin/nginx -V

posted on 2022-02-23 17:46  BlogZhang  阅读(289)  评论(0编辑  收藏  举报

导航