1.安装gcc
yum install gcc-c++
2.安装zlib
yum install -y zlib zlib-devel
3.安装openssl
yum install -y openssl openssl-devel
4.下载nginx linux版本
下载地址:http://nginx.org/download/
5.上传安装包,后解压 tar -zxvf nginx-1.8.0.tar.gz
6.配置并且安装 cd nginx-1.8.0 ./configure make && make install
如果报以下错误:
make: *** 没有规则可以创建“default”需要的目标“build”。 停止。
说明缺少依赖pcre-devel,执行以下命令安装依赖。
yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel
7.查看安装路径 whereis nginx nginx: /usr/local/nginx
8.启动nginx cd /usr/local/nginx/sbin ./nginx
9.查看是否启动成功 ps -ef | grep -v grep | grep nginx root 4772 1 0 18:27 ? 00:00:00 nginx: master process ./nginx nobody 4773 4772 0 18:27 ? 00:00:00 nginx: worker process
nginx默认监听80端口
10.测试(一般服务器默认开启80端口) http://你的域名/
11.安装ssl模块
查看 nginx是否安装了http_ssl_module 模块
[root@xxxx sbin]# ./nginx -V
nginx version: nginx/1.21.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_ssl_module
如果没有出现 configure arguments: –with-http_ssl_module, 则未安装http_ssl_module 模块。
进入nginx源码包,重新执行下面命令。
./configure --with-http_ssl_module
make
然后用源码包中刚刚编译好的nginx可执行文件把安装目录中的nginx可执行文件替换掉。
systemctl stop nginx
cp ./objs/nginx /usr/local/nginx/sbin/
再次重启nginx即可。