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使用

待续…

相关文章

Nginx 从安装到高可用入门教程

Nginx安装1、去官网http://nginx.org/下载对应的nginx包,推荐使用稳定版本2、上传nginx到linux系统3、安装依赖环境(1)安装gcc环境yum install gcc-...

Nginx从安装到高可用,一篇搞定

一、Nginx安装1、去官网http://nginx.org/下载对应的nginx包,推荐使用稳定版本2、上传nginx到linux系统3、安装依赖环境(1)安装gcc环境yum install gc...

Nginx合集-常用功能指导

1)启动、重启以及停止nginx进入sbin目录之后,输入以下命令#启动nginx ./nginx #指定配置文件启动nginx ./nginx -c /usr/local/nginx/conf/n...

Nginx的启动、停止与重启方法

启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址例如:[root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/...

nginx启动、重启、关闭

一、启动cd usr/local/nginx/sbin./nginx二、重启更改配置重启nginxkill -HUP 主进程号或进程号文件路径或者使用cd /usr/local/nginx/sbin....

老版本nginx存在安全漏洞,请升级至1.18稳定版本

1、场景介绍部门承接了XXX局的安全防控系统,物理机部署在本地XX云上,web服务器使用nginx服务,采用动静分离的部署方式,nginx版本1.14,应XX云安全检测要求现版本暴出漏洞,需要进行版本...