CentOS 7.8 安裝 Nginx
一、Linux 軟件安裝方式
- 通过yum安装
- 通过rpm安装
- 通过源码安装
三种安装方式各有差异,yum形式类似于npm安装,简单快捷,自动安装相关依赖;rpm安装与yum类似,只不过安装的模块来源不是yum官方镜像,而是本地资源;源码安装需要下载源码然后本机编译,可以实现个性化定制,适用于对linux了解较多的进阶用户使用。
本文是介绍使用源码编译安装。
二、安裝Nginx
默认已经安装了yum
- 安装准备环境
# gcc
yum -y install gcc
# gcc-c++
yum -y install gcc-c++
# make
yum -y install gcc automake autoconf libtool make
- 一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
# 选定源码目录:
cd /usr/local/src
# 下载、编译、安装PCRE
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install
# 下载、编译、安装zlib
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
# 安装 ssl
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
- 安装 Nginx
# 进到此目录下
cd /usr/local/src
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure
make && make install
- 启动 Nginx
# 进入目录
cd /usr/local/nginx/sbin
# 启动
./nginx
- 查看 Nginx 服务
ps -ef | grep nginx
root 14532 1 0 Sep28 ? 00:00:00 nginx: master process ./nginx
nobody 14533 14532 0 Sep28 ? 00:00:00 nginx: worker process
root 15002 14984 0 01:30 pts/1 00:00:00 grep --color=auto nginx
- 访问当前Linux地址
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
三、Nginx常用命令
# 进入Nginx目录中
cd /usr/local/nginx/sbin
# 查看 nginx 版本号
./nginx -v
# 启动 nginx
./nginx
# 停止 nginx
./nginx -s stop
# 重新加载 nginx
./nginx -s reload
浙公网安备 33010602011771号