centos7.6安装nginx

作者: Gswu | 来源:发表于2019-03-18 19:05 被阅读12次

    系统基础环境:virtualbox下CentOS-Minimal-1810

    1安装方法一:源码编译安装

    基础环境 centos7.6 mini

    目录:/usr/local/src

    1、安装前准备(根据各软件最新版本信息更改url)

    下载nginx、openssl、zlib、pcre

    cd /usr/local/src
    
    wget http://nginx.org/download/nginx-1.10.2.tar.gz
    wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
    wget http://zlib.net/zlib-1.2.11.tar.gz
    wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
    

    2安装(顺序不要错)

    安装make

    yum -y install gcc automake autoconf libtool make
    

    安装gcc编译环境

    # yum install gcc-c++
    

    安装pcre

    # tar zxvf pcre-8.43.tar.gz
    
    # cd pcre-8.40
    
    # ./configure && make && make install
    

    安装openssl:

    tar zxvf openssl-fips-2.0.10.tar.gz
    cd openssl-fips-2.0.10
     ./config && make && make install
    

    安装zlib

    tar zxvf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure && make && make install
    

    安装nginx

    tar zxvf nginx-1.10.2.tar.gz
    
    cd nginx-1.10.2
    
    ./configure && make && make install
    

    这样安装完成后,nginx的路径为/usr/local/nginx/sbin/nginx

    2安装方法二:

    查看CentOS的版本

    cat /etc/redhat-release
    

    添加资源库

    在 CentOS 系统上安装 Nginx ,得先去添加一个资源库:

    vim /etc/yum.repos.d/nginx.repo
    
      [nginx]
    
      name=nginx repo
    
      baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    
      gpgcheck=0
    
      enabled=1
    

    安装nginx

    yum -y install nginx
    

    使用命令

    systemctl stop nginx.service  #停止nginx服务
    systemctl start nginx.service  #打开nginx服务
    systemctl restart nginx.service  #重启nginx服务
    systemctl status nginx.service  #查看nginx服务状态
    

    验证nginx安装成果:

    开启nginx,

    cd /usr/local/nginx/sbin
    ./nginx
    或
    systemctl start nginx.service
    验证:
    curl http://localhost
    

    应该能输出Welcome to nginx的html文件,说明安装启动成功。

    开启外部访问

    centos7默认开启了防火墙模块firewalld,可以查看一下是否开启

    [root@localhost ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
       Active: active (running) since Mon 2019-03-18 10:12:46 EDT; 34s ago
         Docs: man:firewalld(1)
     Main PID: 3618 (firewalld)
       CGroup: /system.slice/firewalld.service
               └─3618 /usr/bin/python -Es /usr/sbin/firewalld --nofork...
    
    Mar 18 10:12:46 localhost.localdomain systemd[1]: Starting firewal...
    Mar 18 10:12:46 localhost.localdomain systemd[1]: Started firewall...
    Hint: Some lines were ellipsized, use -l to show in full.
    

    或者:

    [root@localhost ~]# firewall-cmd --state
    running
    

    关闭firewalld,然后在虚拟机外可以访问

    systemctl stop firewalld #关闭
    systemctl start firewalld #打开
    systemctl restart firewalld #重启
    systemctl disable firewalld #关闭开机启动
    systemctl enable firewalld #开机启动
    
    image.png

    相关文章

      网友评论

        本文标题:centos7.6安装nginx

        本文链接:https://www.haomeiwen.com/subject/kebbmqtx.html