nginx-1.22.1在linux服务器上的安装
一、环境准备
1、gcc安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install gcc gcc-c++
2、pcre pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。Nginx的http 模块使用pcre来解析正则表达式,所以需要在Linux上安装pcre库,pcre-devel 是使用pcre开发的一个二次开发库。Nginx也需要此库。命令:
yum install -y pcre pcre-devel
3、 zlib安装
zlib 库提供了很多种压缩和解压缩的方式, Nginx使用zlib对http包的内容进行gzip,所以需要在Linux Centos 7上安装zlib库。
yum install -y zlib zlib-devel
4、openssl安装
OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
Nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在Linux Centos 7安装OpenSSL库。
yum install -y openssl openssl-devel
二、安装Nginx
1、下载
用wget命令下载(推荐)。确保系统已经安装了wget,如果没有安装,执行 yum install wget 安装。
#下载,这里也可以去官网下载
wget -c https://nginx.org/download/nginx-1.22.1.tar.gz
#解压
tar -zxf nginx-1.22.1.tar.gz -C ./
cd nginx-1.22.1
2、检查配置并指定安装参数
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module
- ./configure 是编译前检查的命令,
- —prefix=/usr/local/nginx 是安装到指定目录,
- —with-http_stub_status_module —with-http_ssl_module 是安装ssl证书的两个模块
3、编译安装
make&&make install
4、操作
#进入目录
cd /usr/local/nginx/sbin/
./nginx #启动
./nginx -s quit # 此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop # 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -t #校验配置文件是否正确
./nginx -s reload #重新加载
5、查看进程
ps -ef|grep nginx
root 4337 1 0 06:13 ? 00:00:00 nginx: master process ./nginx
nobody 4338 4337 0 06:13 ? 00:00:00 nginx: worker process
root 4340 1494 0 06:13 pts/0 00:00:00 grep --color=auto nginx
6、关闭防火墙或者打开80端口
启动: systemctl start firewalld
停止: systemctl stop firewalld
查看所有打开的端口: firewall-cmd --permanent --list-port
开启端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
关闭端口:firewall-cmd --zone=public --remove-port=80/tcp --permanent
更新防火墙规则: firewall-cmd --reload
我这里选择的是开启80端口
开启端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
[root@localhost sbin]# firewall-cmd --permanent --list-port
80/tcp
7、浏览器访问
这里我linux服务器的地址是192.168.192.11 ,访问

三、nginx使用
待续…