?
Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 BSD 许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。
Nginx官方地址:http://nginx.org/en/
Nginx中文文档:http://www.nginx.cn/doc/
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应。
作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。
作为邮件代理服务器:?Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器)。
Nginx 安装非常的简单,配置文件 非常简洁,Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。
yum -y install pcre-devel openssl openssl-devel gcc+c--
[root@localhost~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/
[root@localhost~]# cd /usr/local/src/libevent-2.0.16-stable/
[root@localhost libevent-2.0.16-stable]# ./configure --prefix=/usr/local/libevent
[root@localhost libevent-2.0.16-stable]# make && make install
[root@localhost libevent-2.0.16-stable]# cd /usr/local/libevent/
[root@localhost libevent]# ln -s /usr/local/libevent/include /usr/include/libevent
[root@localhost libevent]# vim /etc/ld.so.conf.d/libevent.conf
#tar –zxvf nginx-1.6.2.tar.gz
#./configure --user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-cc-opt=‘-O2‘ --with-cpu-opt=opteron
#make
#make install
#/usr/local/nginx/sbin/nginx -t
#/usr/local/nginx/sbin/nginx
#ps –ef|grep nginx
到这里nginx的安装已经完成了,接下来添加nginx的代理服务
user root;
#工作进程,一般根据CPU核数来定
worker_processes 2;
server {
listen 9457;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
#这里配上项目地址的分发
location /YourProject1/ {
proxy_pass http://127.0.0.1:8080/YourProject1/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /YourProject2/ {
proxy_pass http://127.0.0.1:8090/YourProject2/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
重启nginxKillall ngnix
#/usr/local/nginx/sbin/nginx
到这里Nginx的简单的安装和配置就完成,当然Nginx还有很多功能,后期可以在这之上不断完善。
附件里是安装Nginx过程中用到的包。
原文:http://wosyingjun.iteye.com/blog/2252941