码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【Linux】环境下部署Nginx服务 - 二进制部署方式


    👨‍🎓博主简介

      🏅云计算领域优质创作者
      🏅华为云开发者社区专家博主
      🏅阿里云开发者社区专家博主
    💊交流社区:运维交流社区 欢迎大家的加入!
    🐋 希望大家多多支持,我们一起进步!😄
    🎉如果文章对你有帮助的话,欢迎 点赞 👍🏻 评论 💬 收藏 ⭐️ 加关注+💗


    文章目录

    • 一、下载安装包
    • 二、部署Nginx服务
      • 1、安装Nginx服务需要的依赖包
      • 2、上传解压
      • 3、编译安装nginx服务
    • 三、启动及确认服务是否正常
    • 四、nginx启动、停止、重启、检测配置命令
    • 五、常见问题
      • 报错1:./configure: error: C compiler cc is not found
      • 报错2:./configure: error: the HTTP rewrite module requires the PCRE library.
      • 问题3:./configure: error: the HTTP gzip module requires the zlib library.
    • 六、nginx配置模块详解
    • 七、相关文章
    • 八、推荐一个自动生成nginx配置文件的网站

    在这里插入图片描述

    一、下载安装包

    官网下载地址:nginx: download

    选择Stable version版本下载到本地(该版本为Linux版本),下载完成后上传到服务器上;

    在这里插入图片描述

    • 或者在服务器上使用wget下载
    wget https://nginx.org/download/nginx-1.24.0.tar.gz
    
    • 1

    二、部署Nginx服务

    1、安装Nginx服务需要的依赖包

    yum -y install gcc gcc-c++ zlib zlib-devel pcre-devel openssl openssl-devel 
    
    • 1

    离线包下载地址:nginx1.24.0 二进制安装离线包及依赖包

    2、上传解压

    (1)sz先把nginx压缩包复制到虚拟机/服务器上
    (2)解压nginx压缩包:

    tar xf nginx-1.24.0.tar.gz -C /usr/src/
    
    • 1

    (3)切换到nginx目录下:

    cd /usr/src/nginx-1.24.0
    
    • 1

    3、编译安装nginx服务

    指定安装路径然后编译安装

    ./configure --prefix=/usr/local/nginx
    make
    make install 
    
    #或者使用下面这一条命令。上面的看着清晰,在哪里错了,易排查问题
    ./configure --prefix=/usr/local/nginx && make && make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    三、启动及确认服务是否正常

    • 安装成功后,启动Nginx服务:到/usr/local/nginx/sbin目录下,启动服务:
    /usr/local/nginx/sbin/nginx -c  /usr/local/nginx/conf/nginx.conf
    
    • 1
    • 启动成功后,查看进程
    ps -ef | grep nginx
    
    • 1
    • 或者查看端口是否启动(默认端口为80)
    netstat -anput | grep 80
    
    • 1

    在这里插入图片描述

    确定启动之后,页面访问:ip
    即可访问到页面:

    在这里插入图片描述

    四、nginx启动、停止、重启、检测配置命令

    #启动nginx服务
    /usr/local/nginx/sbin/nginx
    /usr/local/nginx/sbin/nginx -c  /usr/local/nginx/conf/nginx.conf
    
    #停止nginx
    /usr/local/nginx/sbin/nginx -s stop
    
    #重启nginx
    /usr/local/nginx/sbin/nginx -s reload
    
    #检测nginx服务配置是否有误
    /usr/local/nginx/sbin/nginx -t
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    五、常见问题

    报错1:./configure: error: C compiler cc is not found

    完整报错:
    ./configure: error: C compiler cc is not found
    
    • 1
    • 2

    原因:没有编译环境
    解决:yum -y install gcc gcc-c++

    报错2:./configure: error: the HTTP rewrite module requires the PCRE library.

    完整报错:
    ./configure: error: the HTTP rewrite module requires the PCRE library.
    You can either disable the module by using --without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using --with-pcre=<path> option.
    
    • 1
    • 2
    • 3
    • 4
    • 5

    原因:缺少pcre-devel库
    解决:yum -y install pcre-devel

    问题3:./configure: error: the HTTP gzip module requires the zlib library.

    完整报错:
    ./configure: error: the HTTP gzip module requires the zlib library.
    You can either disable the module by using --without-http_gzip_module
    option, or install the zlib library into the system, or build the zlib library
    statically from the source with nginx by using --with-zlib=<path> option.
    
    • 1
    • 2
    • 3
    • 4
    • 5

    原因:缺少zlib-devel
    解决:yum -y install zlib-devel

    六、nginx配置模块详解

    这里的图是二进制安装默认的配置,yum安装的与二进制安装的nginx,配置会有差异,但整体大概的说明都是一样的。

    在这里插入图片描述

    主要区域讲解:

    在这里插入图片描述

    七、相关文章

    文章标题文章连接
    【Linux】nginx基础篇 – 介绍及yum安装nginxhttps://liucy.blog.csdn.net/article/details/133928000
    【Linux】环境下部署Nginx服务 - 二进制部署方式https://liucy.blog.csdn.net/article/details/132145067
    nginx配置负载均衡–实战项目(适用于轮询、加权轮询、ip_hash)https://liucy.blog.csdn.net/article/details/133986013
    nginx快速部署一个网站服务 + 多域名 + 多端口https://liucy.blog.csdn.net/article/details/133986102

    八、推荐一个自动生成nginx配置文件的网站

    https://nginxconfig.io/
    可以根据你的业务需求,自动生成负载的配置。

    在这里插入图片描述

    往下面翻,就可以看到配置文件了;

    在这里插入图片描述

  • 相关阅读:
    spark学习笔记(十)——sparkSQL核心编程-自定义函数UDF、UDAF/读取保存数据/五大数据类型
    网络安全(黑客)自学
    [模拟]攻略分队 2022RoboCom省赛D
    Vue.js :实现嵌套对话框的查看按钮
    ELK 企业级日志分析系统
    上海亚商投顾:三大指数小幅下跌 光刻机概念股午后走强
    通过容器启动QAnything知识库问答系统
    【无标题】
    Java基础之《netty(2)—IO模型、BIO介绍、NIO介绍》
    JAVA计算机毕业设计电子病历系统Mybatis+系统+数据库+调试部署
  • 原文地址:https://blog.csdn.net/liu_chen_yang/article/details/132145067
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号