Nginx简介
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器。Nginx作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP代理服务器对外进行服务。nginx网站国内的用户有:百度、新浪、网易、腾讯等等。
优点:高并发(10万并发),部署简单,内存消耗小,成本低。
缺点:rewrite功能不够强大,模块没Apache多。
Nginx的安装
下载Nginx(http://nginx.org/en/download.html),最新的好像是nginx-1.9.3。
下载:wget http://nginx.org/download/nginx-1.9.3.tar.gz
安装:在安装前安装ngxin所需的模块,以及编译c,c++的软件
yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
在Ubuntu下使用如下:
sudo apt-get install libssl-dev
sudo apt-get install libpcre3 libpcre3-dev
下载nginx的第三方模块,动静分离proxy_cache做缓存,下载网址下载最新的文件,和nginx的下包放在一起(http://labs.frickle.com/files/)
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz ./
解压:比如文件下载在/home/andy/目录下
tar xzvf nginx-1.9.3.tar.gz
cd nginx-1.9.3
安装Nginx所需的模块
# nginx -V //可以看到原来的编译选项,下面用到
# ./configure ... --add-module=.. //你的第三方模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --without-http-cache --add-module=../ngx_cache_purge-2.3
编译安装
make //make后不要install,改用手动拷贝。先备份
make install
安装完成后在/usr/local/会多nginx文件夹,然后
cd /usr/local/nginx
启动Nginx
cd sbin
./nginx
重新启动
cd sbin
./nginx -s reload
卸载方法
# 删除nginx,保留配置文件
apt-get remove nginx
#删除配置文件
rm -rf /home/nginx
安装出现的问题
如果启动时出现如下问题时
1:端口被占用
说明:80端口已被占用
netstat -anp | grep 80 查询占用80端口的进程
杀死该进程
kill -s 9 pid(进程id)
2:错误为:./configure: error: the HTTP rewrite module requires thePCRE library.
解决办法:安装pcre-devel模块
yum -y install pcre-devel
3.Ubuntu下用apt-get 代替所有的yum
(配置VMwareUbuntu下的静态ip:
1 将虚拟的网络连接设置为桥接模式
2 sudo ifconfig eth0 192.168.1.155 netmask 255.255.255.0
4.缺少安装的OpenSSL库
make: *** No rule to make target `build', needed by `default'. Stop.
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
ubuntu下解决办法:
apt-get install openssl
apt-get install libssl-dev
centos下解决办法:
yum -y install openssl openssl-devel
安装完毕。