美文网首页
001.Nginx安装

001.Nginx安装

作者: CoderJed | 来源:发表于2020-03-22 16:36 被阅读0次

1. 编译源码安装Nginx

  1. 安装依赖软件

    yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
    
  1. 安装nginx
  • 解压进入nginx目录

    tar -zxvf nginx-1.16.1.tar.gz

  • 安装nginx

    [root@magic nginx-1.16.1]# ./configure
    [root@magic nginx-1.16.1]# make && make install
    
  • nginx安装到了/usr/local/nginx目录下

  1. 启动nginx

    [root@magic ~]# /usr/local/nginx/sbin/nginx 
    
    # 查看启动进程
    [root@magic ~]# ps -ef | grep nginx
    root      7950     1  0 16:11 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
    nobody    7951  7950  0 16:11 ?        00:00:00 nginx: worker process
    
  1. 访问页面

    http://hostname:80/

  2. nginx启停命令

    # 启动
    /usr/local/nginx/sbin/nginx
    # 停止
    /usr/local/nginx/sbin/nginx -s stop
    # 重新加载配置(热加载),并非重启服务
    /usr/local/nginx/sbin/nginx -s reload
    

2. yum安装Nginx

官网地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS

  • 安装yum-utils

    sudo yum install yum-utils -y
    
  • 创建/etc/yum.repos.d/nginx.repo文件

    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    
    [nginx-mainline]
    name=nginx mainline repo
    baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    
  • 重新生成yum缓存

    yum makecache fast
    
  • 安装Nginx

    # 默认安装的是nginx最新稳定版
    # 如果想安装最新的快照版,执行以下命令
    # sudo yum-config-manager --enable nginx-mainline
    
    # 通常我们安装稳定版
    sudo yum install nginx -y
    
  • 启停

    systemctl start nginx
    systemctl stop nginx
    
  • 配置文件目录:/etc/nginx/nginx.conf

相关文章

网友评论

      本文标题:001.Nginx安装

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