CentOS 安装nginx

2018/4/17 posted in  linux

Nginx ("engine x") 是一个高性能、轻量级的HTTP和反向代理服务器,也是一个电子邮件(IMAP/POP3)服务器。

     Nginx的最大优势在于高负载情况下内存和CPU的低消耗;并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动;在高连接并发的情况下,Nginx是Apache服务器不错的替代品:能够支持高达 50,000 个并发连接数的响应。

环境:Centos6.6

一:准备工作

首先安装缺少的依赖包
[root@localhost ~]# yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel

二:下载并安装nginx

nginx官网地址:http://nginx.org
最新版nginx获取地址:http://nginx.org/download

下载nginx安装包地址:wget http://nginx.org/download/nginx-1.8.1.tar.gz

[root@localhost ~]# wget http://nginx.org/download/nginx-1.8.1.tar.gz

[root@localhost ~]# tar -zxvf nginx-1.8.1.tar.gz
#解压缩nginx安装包

[root@localhost ~]# cd nginx-1.8.1
#切到nginx安装包下

[root@localhost nginx-1.8.1]# ./configure --with-http_stub_status_module --with-http_ssl_module
#根据需求编译安装(默认路径:/usr/local/nginx)

#--with-http_stub_status_module  启用 "server status" 页,用来监控 Nginx 的当前状态

#--with-http_ssl_module  开启HTTP SSL模块,使NGINX可以支持HTTPS请求

#在不同版本间,选项可能会有些许变化,请总是使用 ./configure --help 命令来检查一下当前的选项列表

[root@localhost nginx-1.8.1]# make
[root@localhost nginx-1.8.1]# make install

三:启动nginx服务
[root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx

四:测试
启动完nginx之后,直接在浏览器键入http://localhost或http://本机IP,会看到nginx的测试页面na

./configure --sbin-path=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid   --with-http_ssl_module --with-pcre=/opt/pcre-8.42 --with-zlib=/opt/zlib-1.2.11 --with-openssl=/opt/openssl-1.1.0h

./configure --user=www-data --group=www-data --with-debug --with-http_gzip_static_module --with-http_ssl_module --with-pcre=../pcre-8.38/ --with-http_perl_module --with-perl=/usr/bin/perl --with-http_stub_status_module --with-http_realip_module --prefix=/usr/local/nginx