• CentOS 7 安装 nginx


    CentOS 7 安装 nginx

    1. 官网下载 nginx

    nginx官网下载链接:http://nginx.org/en/download.html

    在这里插入图片描述
    下载稳定版即可

    2. 将压缩包上传到 CentOS 7 虚拟机中

    这里由于上传工具很多,不予展示

    3. 安装步骤

    1. 检查是否存在 nginx(有的话需要卸载掉自带的):
    whereis nginx
    rm -rf [nginx文件]
    
    • 1
    • 2
    1. 下载安装nginx所需环境:
    yum -y install gcc zlib zlib-devel pcre-devel openssl* openssl-devel ncurses-devel
    
    • 1
    • 安装nginx前需要确保linux上安装了gcc、PCRE 、zlib、OpenSSL
    • 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境。
    • PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:
    • zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
    • OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 CentOS 安装 OpenSSL 库。
    • 执行后等待安装完毕!
    1. 我们一般把解压后需要编译安装的软件压缩包上传至 /opt 文件夹下,找到压缩包并解压:
    tar -zxvf nginx-1.24.0.tar.gz
    
    • 1
    1. 配置nginx:
    # 在 /opt/nginx/nginx-1.24.0 下执行命令
    cd /opt/nginx/nginx-1.24.0
    
    ./configure			#先执行
    
    # 再执行
    # 执行完 make && make install 之后 nginx 会被安装在 /usr/local/ 下(没有指定安装目录会默认安装在 /usr/local/ 下)
    make && make install PREFIX=/usr/local/nginx
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    1. 进入 /usr/local/ 下启动nginx:
    cd /usr/local/nginx
    cd ./sbin		#进入sbin文件
    ./nginx			#启动nginx程序
    
    • 1
    • 2
    • 3
    1. 在Windows上访问Linux下的nginx来确认是否安装成功:

      http://192.168.25.201:80

    在这里插入图片描述

    4. nginx 常用命令

    ./nginx -s stop		#停止nginx
    ./nginx	-s quit		#安全退出
    ./nginx -s reload	#修改了文件之后重新加载该程序文件
    ps -aux | grep nginx	#查看nginx进程
    
    • 1
    • 2
    • 3
    • 4

    5. nginx 修改配置文件

    # 进入 nginx 的 conf 目录下
    cd /usr/local/nginx/conf
    
    # 修改 nginx.conf 文件
    vim nginx.conf
    
    # 修改完配置文件一定要重新加载该程序文件
    ./nginx -s reload
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    【draw】draw.io怎么设置默认字体大小
    华为HCIP题库h12-821题库新增30题
    MC红显材质包安装
    Java Annotation Processor注解处理器如何Debug
    MySQL深度剖析及面试秘籍(必知必会30题全)
    P5960【模板】差分约束
    Elasticsearch script在reindex与script_fields script get当中的应用
    谁用谁夸,超好用的电子期刊制作网站
    使用LIO-SAM进行点云赋色 与 激光雷达和相机的精细化标定(防止自己忘记的博客)----- 激光雷达和相机的精细化标定
    浅谈安科瑞电力监控系统在百事亚洲研发中心的应用
  • 原文地址:https://blog.csdn.net/ONEBEYONDFANS/article/details/133922929