环境:vbox +centos7
基本可以yum安装 gcc 、pcre、zlib、openssl等,此处部分文件手动下载安装
1.下载依耐包:
gcc :yum install gcc
2.下载openssl:
wget https://www.openssl.org/source/openssl-3.0.10.tar.gz --no-check-certificate
安装过程会报错:Can‘t locate IPC/Cmd.pm in @INC 运行yum -y install perl-IPC-Cmd 解决
如果没有先安装gcc,也可能会出错。
成功如下:
3.下载zlib:wget http://zlib.net/current/zlib.tar.gz
解压后进入目录文件下输入:./configure 然后make && make install
4.下载pcre2:
Download pcre2-10.37.tar.gz (PCRE)
解压就可以了,用于后面的nginx 配置,写上此处解压的目录
5.下载nginx:
wget nginx: download
解压后
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=../pcre2-10.37 --with-zlib=../zlib-1.3
--with-http_ssl_module:开启https 443
--with-pcre :用于路由重写 sets the path to the sources of the PCRE library. The library distribution needs to be downloaded from the PCRE site and extracted. The rest is done by nginx’s ./configure
and make
. The library is required for regular expressions support in the location directive and for the ngx_http_rewrite_module module.
--with-zlib:ngx_http_gzip_module 需要用到, 主要用于压缩文件
完成后 make && make install
最后
cd /usr/local/nginx
./nginx
开启nginx后,查看进程 ps ef|grep nginx
访问IP地址能看到welcome to nginx代表安装成功
如果不能成功,需要开启防火墙的端口
nginx服务指令 nginx -s stop /quit /reload /reopen
如果运行重启指令时提示:nginx: command not found
需要添加nginx到环境变量中
vi /etc/profile
文末添加(后面的路径根据当时配的sbin-path路径来):
export PATH=/usr/local/nginx/:$PATH
重启资源
source /etc/profile