Nginx web 入门简介
ginx [engine x] 是 Igor Sysoev 编写的一个 HTTP 和反向代理服务器, 另外它也可以
作为邮件代理服务器. 它已经在众多流量很大的俄罗斯网站上使用了很长时间, 这些网站
包括 Yandex,Mail.Ru,VKontakte, 以及 Rambler.
据 Netcraft 统计, 在 2012 年 8 月份, 世界上最繁忙的网站中有 11.48% 使用 Nginx
作为其服务器或者代理服务器. 目前互联网主流公司 360, 百度, 新浪, 腾讯, 阿里等都在
使用 nginx 作为自己的 Web 服务器.
Nginx 由内核和模块组成, 其中, 内核的设计非常微小和简洁, 完成的工
作也非常简单, 仅仅通过查找配置文件将客户端请求映射到一个
location block(location 是 Nginx 配置中的一个指令, 用于 URL
匹配), 而在这个 location 中所配置的每个指令将会启动不同的模
块去完成相应的工作.
Nginx 相对于 Apache 优点:
1) 高并发响应性能非常好, 官方 Nginx 处理静态文件并发 5w/s
2) 反向代理性能非常好.(可用于负载均衡)
3) 内存和 CPU 占用率低.(为 Apache 的 1/5-1/10)
4) 功能较 Apache 少 (常用功能均有)
5) 对 PHP 可使用 CGI 方式和 fastcgi 方式.
Nginx Web 安装配置
首先需要安装 pcre 库, 然后再安装 Nginx:
# 安装 pcre 支持 rewrite 库, 也可以安装源码, 注 * 安装源码时, 指定 pcre 路径为解压
源码的路径, 而不是编译后的路径, 否则会报错.
- (make[1]: *** [/usr/local/pcre/Makefile] Error 127 错误)
- yum install pcre-devel pcre -y
- # 下载 Nginx 源码包
- cd /usr/src ;wget -c http://nginx.org/download/nginx-1.4.2.tar.gz
- # 解压 Nginx 源码包
- tar -xzf nginx-1.4.2.tar.gz
- # 进入解压目录, 然后 sed 修改 Nginx 版本信息为 WS
- cd nginx-1.4.2 ; sed -i -e 's/1.4.2//g' -e 's/nginx\//WS/g' -e
- 's/"NGINX"/"WS"/g' src/core/nginx.h
- # 预编译 Nginx
- useradd www ;./configure --user=www --group=www
- --prefix=/usr/local/nginx --with-http_stub_status_module
- --with-http_ssl_module
- #.configure 预编译成功后, 执行 make 命令进行编译
- make
- #make 执行成功后, 执行 make install 正式安装
- make install
资源由 www.eimhe.com 美河学习在线收集分享
# 自此 Nginx 安装完毕
/usr/local/nginx/sbin/nginx -t 检查 nginx 配置文件是否正确, 返回 OK 即正确.
- [root@localhost ~]# /usr/local/nginx/sbin/nginx -t
- nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
- nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
- [root@localhost ~]#
然后启动 nginx,/usr/local/nginx/sbin/nginx 回车即可. 查看进程是否已启动:
- [root@localhost ~]# ps -ef |grep nginx
- nobody 5381 30285 0 May16 ? 00:04:31 nginx: worker process
- root 30285 1 0 2014 ? 00:00:00 nginx: master process
- /usr/local/nginx/sbin/nginx
- root 32260 32220 0 12:34 pts/0 00:00:00 grep nginx
来源: http://www.bubuko.com/infodetail-2877795.html