Centos7 源码安装nginx-1.22.1

1、安装wget

yum install -y wget

2、下载nginx源码包并解压

# 下载源码包
wget http://nginx.org/download/nginx-1.22.1.tar.gz
# 解压
tar -xvzf nginx-1.22.1.tar.gz 

 3、安装依赖包

yum install -y gcc pcre-devel openssl-devel

4、创建用户

groupadd nginx
useradd -g nginx -s /sbin/nologin nginx

5、安装nginx

# 进入目录
cd nginx-1.22.1
# 配置
./configure \
--prefix=/usr/local/nginx #指定安装目录
--user=nginx              #指定用户
--group=nginx             #指定用户组
--with-http_ssl_module    #开启ssl加密功能
# 编译安装
make && make install

6、配置nginx.conf

# 备份配置文件
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
# 编辑配置文件
vim /usr/local/nginx/conf/nginx.conf

端口修改为8089

Centos7 源码安装nginx-1.22.1_第1张图片

 7、开启防火墙

# 开启端口8089
firewall-cmd --zone=public --add-port=8089/tcp --permanent
# 重启防火墙
firewall-cmd --reload
# 查看开放的端口
firewall-cmd --list-ports

8、启动nginx

# 启动nginx
cd /usr/local/nginx/sbin/
./nginx
#常用命令
./nginx           #启动nginx
./nginx -s stop   #停止nginx
./nginx -s reload #重新加载nginx
./nginx -V        #查看nginx版本

9、创建软链接启动nginx

# 建立软链接
ln -s /usr/local/nginx/sbin/nginx /usr/sbin
# 启动
nginx
# 查看nginx版本
nginx -V

10、配置nginx开机自启

# 进入目录
cd /usr/lib/systemd/system/
# 编辑文件内容
vim /usr/lib/systemd/system/nginx.service

Centos7 源码安装nginx-1.22.1_第2张图片

 11、启动服务

# 启动服务之前,需要先重载systemctl命令
systemctl daemon-reload
systemctl start nginx.service
systemctl enable nginx
#配置systemctl之后的启动方式
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx

12、重启系统,查看nginx是否成功自启动

reboot
systemctl status nginx

13、查看端口使用工具netstat

参数:

-a 查看所有端口的信息

-n 数字形式显示端口号

-t 查看使用tcp协议的端口

-u 查看使用udp协议的端口

-p 查看使用端口的程序名

常用组合:netstat -anp

你可能感兴趣的:(nginx,nginx,linux,centos)