0.版本说明
环境:centos7.9
版本:nginx-1.20.2
1.安装插件
1.1.插件gcc
查看gcc版本
gcc -v
没有安装的话,安装命令如下
yum -y install gcc
1.2.插件pcre、pcre-devel
pcre、pcre-devel安装
yum install -y pcre pcre-devel
1.3.插件zlib
zlib安装
yum install -y zlib zlib-devel
1.4.插件openssl
openssl安装
yum install -y openssl openssl-devel
2.安装Nginx
2.1.解压安装包
cd /opt/software
tar -zxvf nginx-1.20.2.tar.gz
2.2.安装nginx
cd /opt/software/nginx-1.20.2
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module #自定义安装目录并且开启SSL模块
make
make install
3.配置nginx.conf文件
位置:/opt/nginx/conf/nginx.conf
3.1.追加自定义配置文件,在文件的最后追加以下代码,目的是所有自定义的配置文件,都单独写,不影响nginx.conf本身
# 引用自定义配置 开始
include vhost/*.conf;
# 引用自定义配置 结束
3.2.一些其他的配置修改
在http标签内,追加或修改以下配置
#上传文件大小限制
client_max_body_size 100M;
#设置为on表示启动高效传输文件的模式
sendfile on;
#保持连接的时间,默认是65
keepalive_timeout 1800;
在events标签内,修改配置
events {
#单个进程允许的客户端最大连接数
worker_connections 65535;
#使用epoll模型
use epoll;
}
4.启动nginx服务
启动命令如下
cd /opt/nginx/sbin
./nginx
查看nginx服务是否启动成功
ps -ef | grep nginx
访问你的服务器IP,正常显示欢迎页面

image.png
5.设置开机自启动
进入到/usr/lib/systemd/system/目录
cd /usr/lib/systemd/system/
创建nginx.service文件,内容如下
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx
PrivateTmp=true
[Install]
WantedBy=multi-user.target
加入开机自启动
systemctl enable redis.service
一些命令
systemctl start redis.service #启动redis服务
systemctl stop redis.service #停止redis服务
systemctl restart redis.service #重新启动服务
systemctl status redis.service #查看服务当前状态
systemctl enable redis.service #设置开机自启动
systemctl disable redis.service #停止开机自启动
5.结束语
本篇只记录自己的学习过程,更好的提升自己