centos 7 安装Nginx详解

序言

NGINX是一个免费的,开源的,高性能的HTTP服务器和反向代理,以及IMAP / POP3代理服务器。NGINX以其高性能,稳定性,丰富的功能集,简单的配置和低资源消耗而闻名。

一、官网下载安装包

下载地址:http://nginx.org/download/ 里面包含 nginx 各个版本的安装包

wget   -P  /tmp/nginx/   http://nginx.org/download/nginx-1.14.0.tar.gz    
wget命令 参数:
-P  –directory-prefix=PREFIX 将文件保存到目录 PREFIX/…   目录不存在时会自己创建
-O  –output-document=FILE 把文档写到FILE文件中    在指定路径的时候,目录要先自己创建

在这里插入图片描述

二、安装nginx依赖库

yum install gcc-c++          #gcc是用来编译下载下来的nginx源码
yum install pcre             #是一个Perl库,包括 perl 兼容的正则表达式库
yum install pcre-devel  	 #pcre-devel 是使用 pcre 开发的一个二次开发库
yum install zlib             #zlib提供了很多压缩和解方式,nginx需要zlib对http进行gzip
yum install zlib-devel       #zlib-devel 是使用 zlib开发的一个二次开发库
yum install openssl          #openssl是一个安全套接字层密码库,nginx要支持https,需要使用openssl
yum install openssl-devel    #openssl-devel 是使用 openssl开发的一个二次开发库

三、配置nginx用户和组

//添加nginx用户和组 
groupadd nginx
useradd -s /sbin/nologin -M nginx  -g nginx

四、安装nginx

  1. 解压nginx安装包
    tar -zxvf nginx-1.14.0.tar.gz
    
  2. cd到文件路劲
    在这里插入图片描述
  3. 编译
    mkdir -p  /var/tmp/nginx/client  /var/tmp/nginx/proxy  /var/tmp/nginx/fcgi
    ./configure \
    --prefix=/usr  \
    --sbin-path=/usr/sbin/nginx  \
    --conf-path=/etc/nginx/nginx.conf  \
    --error-log-path=/var/log/nginx/error.log \
    --pid-path=/var/run/nginx/nginx.pid \
    --lock-path=/var/lock/nginx.lock \
    --user=nginx \
    --group=nginx \
    --with-http_ssl_module \
    --with-http_gzip_static_module \
    --http-log-path=/var/log/nginx/access.log \
    --http-client-body-temp-path=/var/tmp/nginx/client \
    --http-proxy-temp-path=/var/tmp/nginx/proxy \
    --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
    --with-http_stub_status_module	
    
  4. 安装
    make && make install
    
  5. 防火墙配置
    #centos7里面 使用的是firewall  要是用不习惯可以换iptables
    sudo firewall-cmd --permanent --zone=public --add-service=http 
    sudo firewall-cmd --permanent --zone=public --add-service=https
    sudo firewall-cmd --reload
    #切换为iptables防火墙
    service firewalld stop
    systemctl disable firewalld.service #禁止firewall开机启动
    yum install iptables-services #安装
    vim /etc/sysconfig/iptables #编辑防火墙配置文件
    iptables -I INPUT -p tcp --dport 80 -j ACCEPT
    iptables -I INPUT -p tcp --dport 443-j ACCEPT
    

五、启动nginx

  nginx -c /etc/nginx/nginx.conf   #启动
  nginx -s reload                  #配置文件修改重装载命令
  nginx -s stop                    #快速停止或关闭Nginx
  nginx -s quit                    #正常停止或关闭Nginx

六、验证

在这里插入图片描述
在这里插入图片描述
curl -i http://127.0.0.1

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值