• Centos7 安装 Nginx


    官网
    在这里插入图片描述

    前提准备

    yum -y install gcc-c++
    yum -y install pcre
    yum -y install pcre-devel
    yum -y install zlib
    yum -y install zlib-devel
    yum -y install openssl
    yum -y install openssl-devel
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    开放80端口

    firewall-cmd --query-port=80/tcp
    
    firewall-cmd --add-port=80/tcp --permanent
    
    firewall-cmd --reload
    
    • 1
    • 2
    • 3
    • 4
    • 5

    下载nginx

    我把nginx下载到了/usr/local目录下了

    wget https://nginx.org/download/nginx-1.22.0.tar.gz
    
    • 1

    如果没有wget命令,就安装一下wget

    yum -y install wget
    
    • 1

    解压

    tar -zxvf nginx-1.22.0.tar.gz
    
    • 1

    进入nginx

    cd nginx-1.22.0
    
    • 1

    执行编译命令 一步一步来

    ./configure
    
    make
    
    make install
    
    • 1
    • 2
    • 3
    • 4
    • 5

    配置nginx开机启动

    在/lib/systemd/system目录下,创建nginx.service文件vi nginx.service

    cd /lib/systemd/system/
    vi nginx.service
    
    • 1
    • 2
    [Unit]
    Description=nginx 
    After=network.target 
       
    [Service] 
    Type=forking 
    ExecStart= /usr/local/nginx/sbin/nginx
    ExecReload= /usr/local/nginx/sbin/nginx  reload
    ExecStop= /usr/local/nginx/sbin/nginx  quit
    PrivateTmp= true 
       
    [Install] 
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    退出并保存文件,执行systemctl enable nginx.service使nginx开机启动

    systemctl enable nginx.service
    
    • 1

    启动

    systemctl start nginx.service    启动nginx
    
    • 1

    停止和重启

    systemctl stop nginx.service    结束nginx
     
    systemctl restart nginx.service    重启nginx
    
    • 1
    • 2
    • 3

    安装结束~

  • 相关阅读:
    MonkeyRunner测试步骤
    洛谷P1763 埃及分数
    环路与快速破环
    使用 calc 计算保险实际收益率
    设计模式——装饰器模式
    平衡树 Treap & Splay [学习笔记]
    C语言三子棋,五子棋,n子棋的代码实现
    【mysql索引实现原理】
    halcon算子3、emphasize
    spring5.0 源码解析 populateBean 10
  • 原文地址:https://blog.csdn.net/weixin_41999594/article/details/125465176