技术员联盟提供win764位系统下载,win10,win7,xp,装机纯净版,64位旗舰版,绿色软件,免费软件下载基地!

当前位置:主页 > 教程 > 服务器类 >

CentOS 7.2如何安装Nginx 1.10.2

来源:技术员联盟┆发布时间:2017-04-13 10:05┆点击:

  一、使用Yum安装(推荐)

  使用Yum安装是推荐的方式,整体的流程非常的简单,也不容易出错,如果不需要什么特殊配置,建议使用Yum尽进行安装。

  1、安装epel-release源并进行安装

  yum install epel-release

  yum update

  yum install nginx

  2、执行相关的应用操作

  systemctl start nginx #启动

  systemctl stop nginx #停止

  systemctl restart nginx #重启

  systemctl status nginx #查看运行状态

  systemctl enable nginx #开机启动

  3、设置防火墙

  在启动完以后可能无法通过IP访问,需要进一步设置防火墙

  firewall-cmd --permanent --zone=public --add-service=http

  firewall-cmd --permanent --zone=public --add-service=https

  firewall-cmd --reload

  至此,安装完毕。

  参考文章:https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

  二、通过源码编译安装

  1、安装编译所需工具

  yum groupinstall "Development Tools"

  yum install wget

  2、到官网下载最新的源代码(https://nginx.org/en/)

  cd /usr/local/src

  wget

  tar zxvf nginx-1.10.2.tar.gz

  3、安装依赖包

  yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel

  zlib: 为nginx提供gzip模块,需要zlib库支持,传输数据打包,省流量(但消耗资源)

  openssl: 为nginx提供ssl功能

  pcre: 为支持地址重写rewrite功能

  4、创建用来运行nginx的用户及组

  groupadd nginx

  useradd -g nginx -M nginx –s /sbin/nologin

  -g参数为nginx用户指定了一个组。-M参数保证其不自动生成home目录。

  5、编译源代码

  先使用./configure –help 查看编译帮助:

  [root@localhost nginx-1.10.2]# ./configure --help

  --help print this message

  --prefix=PATH set installation prefix #Nginx安装的根路径,默认为 /usr/local/nginx。

  --sbin-path=PATH set nginx binary pathname #指定nginx二进制文件的路径,默认为PATH/sbin/nginx。

  --modules-path=PATH set modules path #Perl模块位置

  --conf-path=PATH set nginx.conf pathname #设定nginx配置文件地址,默认为PATH/conf/nginx.conf。

  --error-log-path=PATH set error log pathname #错误文件路径,默认为 PATH/logs/error.log。

  --pid-path=PATH set nginx.pid pathname # master进程pid写入的文件位置,通常在var/run下,默认为 PATH/logs/nginx.pid。

  --lock-path=PATH set nginx.lock pathname #共享存储器互斥锁文件路径

  --user=USER set non-privileged user for worker processes #指定程序运行时的非特权用户

  --group=GROUP set non-privileged group for worker processes #指定程序运行时的非特权用户组

  --build=NAME set build name #编译名称

  --builddir=DIR set build directory #指向编译目录

  --with-select_module enable select module 允许或不允许开启SELECT模式,如果configure没有找到合适的模式,比如,kqueue(sun os)、epoll(linux kenel 2.6+)、rtsig(实时信号)

  --without-select_module disable select module 禁用select模块支持

  --with-poll_module enable poll module 启用poll模块支持(功能与select相同,与select特性相同,为一种轮询模式,不推荐在高载环境下使用)

  --without-poll_module disable poll module 禁用poll模块支持

  --with-threads enable thread pool support

  --with-file-aio enable file AIO support #为freeBSD4.3+和linux2.6.22+系统启用异步io

  --with-ipv6 enable IPv6 support #启用ipv6支持

  #默认禁用的模块

  --with-http_ssl_module enable ngx_http_ssl_module #使支持https请求,需已安装openssl

  --with-http_v2_module enable ngx_http_v2_module #启用HTTP V2

  --with-http_realip_module enable ngx_http_realip_module #此模块支持显示真实来源IP地址,主要用于NGINX做前端负载均衡服务器使用

  --with-http_addition_module enable ngx_http_addition_module #输出过滤器,使你能够在请求经过一个location前或后时在该location本身添加内容

  --with-http_xslt_module enable ngx_http_xslt_module #这个模块是一个过滤器,它可以通过XSLT模板转换XML应答

  --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module

  --with-http_image_filter_module enable ngx_http_image_filter_module #图像过滤器,在将图像投递到客户之前进行处理(需要libgd库)

  --with-http_image_filter_module=dynamic

  enable dynamic ngx_http_image_filter_module

  --with-http_geoip_module enable ngx_http_geoip_module #创建基于与MaxMind GeoIP相配的客户端地址

  --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module

  --with-http_sub_module enable ngx_http_sub_module #这个模块可以能够在nginx的应答中搜索并替换文本

  --with-http_dav_module enable ngx_http_dav_module #为文件和目录指定权限,限制不同类型的用户对于页面有不同的操作权限

  --with-http_flv_module enable ngx_http_flv_module #这个模块支持对FLV(flash)文件的拖动播放

  --with-http_mp4_module enable ngx_http_mp4_module #支持H.264/AAC文件为伪流媒体

  --with-http_gunzip_module enable ngx_http_gunzip_module #对于不支持gzip编码的客户,该模块用于为客户解压缩预压缩内容