手把手教你认识并搭建Nginx
2016-07-13 15:33
459 查看
[架构设计]手把手教你认识并搭建Nginx |
手把手教你认识并搭建Nginx 手把手教你认识并搭建Nginx Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 BSD 许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。 一. Nginx 的优点: 作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应。 作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。 作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器)。 Nginx 安装非常的简单,配置文件 非常简洁,Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。 二. 安装Nginx过程(在CentOS上搭建): 安装nginx依赖的插件,建议通过yum进行在线安装。 yum -y install pcre-devel openssl openssl-devel gcc+c-- Pcre-devel是支持读写(支持正则表达式的库)等插件 openssl是支持ssl证书插件 安装libevent(由于nginx采用的是epoll机制需要事件库的支持) [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/ 为了系统能其他的程序能够调用libevent的头文件和库文件我们需要进行下面的操作: [root@localhost libevent]# ln -s /usr/local/libevent/include /usr/include/libevent [root@localhost libevent]# vim /etc/ld.so.conf.d/libevent.conf 加入文件内容如下: root@localhost libevent]# ldconfig 安装nginx过程 解压并配置nginx包 #tar –zxvf nginx-1.6.2.tar.gz 生成新的目录nginx-1.6.2,进入该目录下,配置安装nginx需要的相关配置信息 #./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 安装nginx #make install 检查nginx配置是否正确 #/usr/local/nginx/sbin/nginx -t 启动nginx #/usr/local/nginx/sbin/nginx 查看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; } } 重启nginx Killall ngnix #/usr/local/nginx/sbin/nginx 转载自:http://www.3fwork.com/b300/000751MYM030286/ |
相关文章推荐
- linux下编译安装nginx1.10.1
- ubuntu 源码安装apache和nginx
- nginx geoip 模块实现地区性负载均衡
- Linux内存管理之mmap详解&&nginx子进程间通信
- Nginx初接触
- nginx搭建rtmp协议流媒体服务器总结
- Nginx 配置从零开始
- 购买阿里云CA证书后,如何配置apache和nginx
- 基于windows server2008的nginx 代理上网方案
- linux nginx+php安装
- Nginx配置
- Nginx启动报错误unlink() “nginx.pid” failed (2: No such file or directory)
- nginx负载均衡
- Nginx upstream的5种权重分配方式分享
- 在阿里云 CentOS服务器上搭建nginx+mysql+php环境
- keepalived+nginx双机热备+负载均衡
- Nginx之页面缓存
- nginx中文手册
- nginx 提高性能原理
- php7 使用mysql nginx配置