CentOS 6.6 安装 nginx

来源:互联网 发布:php 跳转url 编辑:程序博客网 时间:2024/06/12 21:02
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,由俄罗斯的程序设计师Igor Sysoev所开发,其特点是占有内存少,并发能力强,第一个公开版本0.1.0发布于2004年10月4日,目前最新版本是2014年12月2日发布的1.7.8。

今天在ttlsa网站里学习了Nginx的安装方法,在虚拟机里测试过,然后又在服务器上安装了一遍,下面我把安装过程总结一下。

Linux系统:Centos 6.5 x64
Nginx版本:1.7.8

1、安装prce(重定向支持)和openssl(https支持,如果不需要https可以不安装。)

  1. yum -y install pcre*
  1. yum -y install openssl*
CentOS 6.5 我安装的时候是选择的“基本服务器”,默认这两个包都没安装全,所以这两个都运行安装即可。

2、下载nginx 1.7.8

  1. wget http://nginx.org/download/nginx-1.7.8.tar.gz
3、解压编译安装

  1. tar -zxvf nginx-1.7.8.tar.gz
然后进入目录编译安装
  1. cd nginx-1.7.8
  1. ./configure --prefix=/usr/local/nginx-1.5.1 \
  2. --with-http_ssl_module --with-http_spdy_module \
  3. --with-http_stub_status_module --with-pcre
如果没有error信息,就可以执行下边的安装了:
  1. make
  2. make install
4、开启nginx进程

  1. /usr/local/nginx-1.7.8/sbin/nginx
重启或关闭进程:
  1. /usr/local/nginx-1.7.8/sbin/nginx -s reload
  2. /usr/local/nginx-1.7.8/sbin/nginx -s stop
5、关闭防火墙,或者添加防火墙规则就可以测试了。

  1. service iptables stop
或者编辑配置文件:

  1. vi /etc/sysconfig/iptables
添加这样一条开放80端口的规则后保存:

  1. -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启服务即可:

  1. service iptables restart
ok,,可以浏览器访问了。

Welcome to nginx!



有时候,我们需要单独安装nginx,来处理大量的下载请求。单独在Centos5安装nginx遇到的rewrite和HTTP cache错误解决办法:

wget http://nginx.org/download/nginx-0.8.33.tar.gz
tar -zxvf nginx-0.8.33.tar.gz 
cd nginx-0.8.33
./configure --prefix=/usr/local/nginx

 

安装Nginx时报错

./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
yum -y install pcre-devel

 

错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决办法:

yum -y install openssl openssl-devel

 

总结:

yum -y install pcre-devel openssl openssl-devel

./configure --prefix=/usr/local/nginx

make

make install

一切搞定


0 0