① Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特色是占有内存少,并发能力强。nginx
② Nginx做为Http服务器,有如下几项基本特征:git
b.1 处理静态文件,索引文件以及自动索引,打开文件描述符缓冲。github
b.2 无缓存的反向代理加速,简单的负载均衡和容错正则表达式
b.3 模块化的结构,包括gzipping,byte ranges,chunked responses以及SSI-filter等filter,若是由FastCGI或其它代理服务器处理蛋液中存在的多个SSI,则这项处理能够并行运行,而不须要相互等待。算法
b.4 支持SSL和TLSSNI。缓存
③ nginx官方网址:http://nginx.org/安全
若是须要搭建直播流媒体服务器,则能够在安装nginx的同时指定一下rtmp-module,这样安装好的nginx服务器就具有直播的功能。服务器
nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module。并发
使用git命令进行下载:负载均衡
git clone https://github.com/arut/nginx-rtmp-module.git
注: 若是没有安装git,能够经过命令 yum groupinstall "Development Tools" 安装相关的软件
nginx拥有ssl功能,gzip模块和rewrite模块,所以安装nginx的时候须要先安装openssl库,zlib库,pcre库。
说明: OpenSSL 是一个安全套接字层密码库,囊括主要的密码算法、经常使用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
官网地址:https://www.openssl.org/source/
安装步骤:
1 wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz 2 tar -zxvf openssl-1.0.2m.tar.gz 3 cd openssl-1.0.2m 4 ./config 5 make 6 make install
说明:zlib是提供数据压缩用的函式库,由Jean-loup Gailly与Mark Adler所开发,第一版0.9版在1995年5月1日发表。zlib使用DEFLATE算法,最初是为libpng函式库所写的,后来广泛为许多软件所使用。此函式库为自由软件,使用zlib受权。
官方网址:http://www.zlib.net/
安装步骤:
1 wget http://www.zlib.net/zlib-1.2.11.tar.gz 2 tar -zxvf zlib-1.2.11.tar.gz 3 cd zlib-1.2.11 4 ./configure 5 make 6 make install
说明: PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。这些在执行正规表达式模式匹配时用与Perl 5一样的语法和语义是颇有用的。Boost太庞大了,使用boost regex后,程序的编译速度明显变慢。测试了一下,一样一个程序,使用boost::regex编译时须要3秒,而使用pcre不到1秒。所以改用pcre来解决C语言中使用正则表达式的问题。
官方网址:http://www.pcre.org/
安装步骤:
1 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.21.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
2 tar -xzvf pcre2-10.21.tar.gz 3 cd pcre2-10.21 4 ./configure 5 make 6 make install
安装完成nginx前置要求事后,就能够开始安装nginx了。
安装步骤:
1 wget http://nginx.org/download/nginx-1.13.6.tar.gz 2 tar -xzvf nginx-1.13.6.tar.gz 3 cd nginx-1.13.6 4 ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_flv_module --add-module=/usr/local/nginx/buildpath/nginx-rtmp-module 5 make 6 make install
注: 编译时指定了用户,目录,若是不须要直播,能够将最后面的--add-module去掉
1 cd /usr/local/nginx/ 2 sbin/nginx -t
3 sbin/nginx
若是启动nginx时出现错误:
这个是因为没有建立nginx的用户,建立用户:
1 useradd -s /sbin/nologin -M nginx 2 id nginx
① 使用命令 vi /etc/init.d/nginx,开发编辑器,输入内容:
1 #!/bin/sh 2 # chkconfig: 2345 85 15 3 # Startup script for the nginx Web Server 4 # description: nginx is a World Wide Web server. 5 # It is used to serve HTML files and CGI. 6 # processname: nginx 7 # pidfile: /usr/local/nginx/logs/nginx.pid 8 # config: /usr/local/nginx/conf/nginx.conf 9 10 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 11 DESC="nginx deamon" 12 NAME=nginx 13 DAEMON=/usr/local/nginx/sbin/$NAME 14 SCRIPTNAME=/etc/init.d/$NAME 15 16 test -x $DAEMON || exit 0 17 18 d_start(){ 19 $DAEMON || echo -n "already running" 20 } 21 22 d_stop(){ 23 $DAEMON -s quit || echo -n "not running" 24 } 25 26 27 d_reload(){ 28 $DAEMON -s reload || echo -n "can not reload" 29 } 30 31 case "$1" in 32 start) 33 echo -n "Starting $DESC: $NAME" 34 d_start 35 echo "." 36 ;; 37 stop) 38 echo -n "Stopping $DESC: $NAME" 39 d_stop 40 echo "." 41 ;; 42 reload) 43 echo -n "Reloading $DESC conf..." 44 d_reload 45 echo "reload ." 46 ;; 47 restart) 48 echo -n "Restarting $DESC: $NAME" 49 d_stop 50 sleep 2 51 d_start 52 echo "." 53 ;; 54 *) 55 echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2 56 exit 3 57 ;; 58 esac 59 60 exit 0
② 接着使用命令:
chmod +x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on
③ 使用命令查看是否启动正常
service nginx start # 启动
service nginx stop # 关闭
开通防火墙,运行nginx端口经过。
而后经过ip进行访问,若是出现,则证实配置成功。