CentOS7 下 Nginx 安装部署

一、Nginx简介

       Nginx是一款高性能的web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡。由俄罗斯人Igor Sysoev(伊戈尔·赛索耶夫)为俄罗斯网站Rambler.ru开发的,在Rambler.ru网站平稳的运行了四年,而且俄罗斯超过20%的虚拟主机平台采用Nginx作为反向代理服务器。
优点:

  • 高并发量:根据官方给出的数据,能够支持高达 50,000 个并发连接数的响应。
  • 内存消耗少:处理静态文件,比apache 占用更少的内存及资源。
  • 简单稳定:配置简单,性能比较稳定,可以7*24小时长时间不间断运行。
  • 模块化程度高:Nginx是高度模块化的设计,编写模块相对简单,包括 gzipping, byte ranges, chunked responses以及 SSI-filter 等 filter,支持 SSL 和 TLSSNI。
  • 支持Rwrite重写规则:能够根据域名、URL的不同, 将HTTP请求分发到不同的后端服务器群组。
  • 低成本:Nginx可以做高并发的负载均衡,且Nginx是开源免费的。
  • 支持多系统:Nginx代码完采用C语言编写,可移植到多种操作系统,包括:Linux、FreeBSD、Solaris、Mac OS X、AIX以及Microsoft Windows,由于Nginx是免费开源的,可以在各系统上编译并使用。

缺点:

  • 与apache相比,Ngnix动态处理差,因此一般前端用Nginx作为反向代理,apache作为后端处理动态请求。
  • 与apache相比,rewrite偏弱。

二、Nginx安装

1、下载相关组件及安装包

  • openssl-fips-2.0.9.tar.gz
  • pcre-8.42.tar.gz
  • zlib-1.2.11.tar.gz
  • nginx-1.8.0.tar.gz

2、安装c++编译环境
[root@localhost Nginx]# yum install gcc-c++

3、安装openssl
[root@localhost Nginx]# tar -zxvf openssl-fips-2.0.9.tar.gz
[root@localhost Nginx]# cd openssl-fips-2.0.9
[root@localhost openssl-fips-2.0.9]# ./config --prefix=/usr/local/nginx/openssl-2.0.9
[root@localhost openssl-fips-2.0.9]# make && make install

4、安装pcre
[root@localhost Nginx]# tar -zxvf pcre-8.42.tar.gz
[root@localhost Nginx]# cd pcre-8.42
[root@localhost pcre-8.42]# ./configure --prefix=/usr/local/nginx/pcre-8.42
[root@localhost pcre-8.42]# make && make install

5、安装zlib
[root@localhost Nginx]# tar -zxvf zlib-1.2.11.tar.gz
[root@localhost Nginx]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure --prefix=/usr/local/nginx/zlib-1.2.11
[root@localhost zlib-1.2.11]# make && make install

6、安装Nginx
[root@localhost Nginx]# tar -zxvf nginx-1.8.0.tar.gz
[root@localhost Nginx]# cd nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --with-http_ssl_module --with-pcre=…/pcre-8.42 --with-zlib=…/zlib-1.2.11 --with-openssl=…/openssl-fips-2.0.9 --prefix=/usr/local/nginx/nginx-1.8.0
[root@localhost nginx-1.8.0]# make && make install

7、检查Nginx是否安装成功
[root@localhost nginx-1.8.0]# cd /usr/local/nginx/nginx-1.8.0/sbin
[root@localhost sbin]# ./nginx -t
在这里插入图片描述
3、Nginx基本操作
[root@localhost sbin]# ./nginx 启动
[root@localhost sbin]# ./nginx -s stop 停止
[root@localhost sbin]# ./nginx -s reload 修改配置后重新加载配置
[root@localhost sbin]# netstat -ntlp 查看tcp是否正常监听
[root@localhost sbin]# ps -aux | grep nginx 查看状态

三、开启外网访问Nginx

       在Centos7中,由firewalld控制防火墙,默认启用远程连接22端口,因此需要开启80端口。
1、firewall开启或关闭端口的方法:

  • 添加:firewall-cmd --zone=public --add-port=80/tcp --permanent
    注:–permanent表示永久生效,没有此参数重启后失效
  • 重新载入:firewall-cmd --reload
  • 查看:firewall-cmd --zone= public --query-port=80/tcp
  • 删除:firewall-cmd --zone= public --remove-port=80/tcp --permanent

2、firewalld-cmd基本操作

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值