Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,能够支支撑5万并发链接,并且cpu、内存等资源消耗却非常低,运行非常稳定。
使用场景:
1、http服务器。Nginx是一个http服务可以独立提供http服务。可以做网页静态服务器。
2、虚拟主机。可以实现在一台服务器虚拟出多个网站。例如个人网站使用的虚拟主机。
3、反向代理,负载均衡。当网站的访问量达到一定程度后,单台服务器不能满足用户的请求时,需要用多台服务器集群可以使用nginx做反向代理。并且多台服务器可以平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况。
安装:
上传解压后进入nginx目录:
[root@localhost ~]# tar -zxf nginx-1.8.0.tar.gz
[root@localhost ~]# cd nginx-1.8.0
[root@localhost nginx-1.8.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.8.0]#
nginx需要的环境:
[root@localhost nginx-1.8.0]# yum install gcc-c++
[root@localhost nginx-1.8.0]# yum install -y pcre pcre-devel
[root@localhost nginx-1.8.0]# yum install -y zlib zlib-devel
[root@localhost nginx-1.8.0]# yum install -y openssl openssl-devel
nginx需要设置的编译参数:
[root@localhost nginx-1.8.0]# ./configure \
> --prefix=/usr/local/nginx \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --with-http_gzip_static_module \
> --http-client-body-temp-path=/var/temp/nginx/client \
> --http-proxy-temp-path=/var/temp/nginx/proxy \
> --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
> --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
> --http-scgi-temp-path=/var/temp/nginx/scgi
[root@localhost nginx-1.8.0]# make
[root@localhost nginx-1.8.0]# make install
测试:
[root@localhost sbin]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx
浏览器查看成功。