Nginx 24.0.5 部署

文档资料

介质路径

安装 Nginx

1. 创建服务目录

mkdir -p /data/service/nginx/nginx_src

2. 下载并解压 Nginx 1.24.0

wget https://nginx.org/download/nginx-1.24.0.tar.gz -P /data/service/nginx
tar -xf /data/service/nginx/nginx-1.24.0.tar.gz -C /data/service/nginx/

3. 安装依赖服务

yum install make zlib zlib-devel pcre pcre-devel gcc* libtool openssl openssl-devel -y

4. 编译 Nginx

cd /data/service/nginx/nginx-1.24.0

# --prefix: 指定 Nginx 安装路径
./configure --prefix=/data/service/nginx/nginx_src

make && make install

5. 配置环境变量

配置环境变量主要用于方便运行 Nginx 命令,并不影响 Nginx 的部署和使用。若无此需求,可跳过此步骤

cat >> /etc/profile << EOF

# Nginx 1.24.0 2024-03-04
export NGINX_HOME=/data/service/nginx/nginx_src
export PATH=$PATH:$NGINX_HOME/bin:$NGINX_HOME/sbin:$NGINX_HOME/lib
EOF

source /etc/profile
  • 验证
nginx -V

# 输出结果
# 能够输出相关信息,则表示环境变量配置成功
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --prefix=/data/service/nginx/nginx_src

配置 Nginx

  • 配置文件路径: $NGINX_HOME/conf/nginx.conf
# 全局块
# 服务进程数量。一般建议与 CPU 内核数保持一致
worker_processes  2;

# 事件块
events {

    # 最大连接数
    worker_connections  1024;
}

# http 块
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    # 客户端连接超时阈值。单位为秒
    keepalive_timeout  65;

    # 服务块
    server {

        # 指定 Nginx 监听端口
        listen       80;

        # 指定客户端连接时所使用的域名
        server_name  nginx-test.com;

        # 位置块
        # 定义根路径的访问规则
        location / {
            root   html;
            index  index.html index.htm;
        }

        # 错误页返回的页面
        error_page   500 502 503 504  /50x.html;

        # 位置块
        # 定义 /50x.html 路径的访问规则
        location = /50x.html {
            root   html;
        }
    }
}
  • 检查配置
nginx -t

# 输出结果
nginx: the configuration file /data/service/nginx/nginx_src/conf/nginx.conf syntax is ok
nginx: configuration file /data/service/nginx/nginx_src/conf/nginx.conf test is successful

启动 Nginx

nginx

检查 Nginx

  • 查看进程
ps -ef | grep -v "grep" | grep nginx

# 输出结果
# 由于所配置的 worker_processes 为 2,所以生成 2 个 worker 进程
# 由于未指定 user,所以进程用户为默认用户 nobody
root     31709     1  0 10:33 ?        00:00:00 nginx: master process nginx
nobody   31710 31709  0 10:33 ?        00:00:00 nginx: worker process
nobody   31711 31709  0 10:33 ?        00:00:00 nginx: worker process
  • 查看端口
netstat -tunlp | grep -w 80

# 输出结果
# 80 端口已处于监听状态
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      31709/nginx: master
  • 通过浏览器,访问地址: 10.10.10.131:80

在这里插入图片描述

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JP.Hu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值