内核版本:
[root@yao ~]# uname -r
2.6.32-431.el6.x86_64
系统版本:
[root@yao ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
nginx的优势
1.作为web服务器,nginx处理静态文件、索引文件,自动索引的运行效利非常高
2.作为代理服务器,nginx可以实现无缓存的反向代理加速,提高网站的运行速度
3.
4.在性能方面,nginx是专门为性能优化而开发的,在实现它采用内核poll模型,可以支持更多的并发。
5.在稳定性上,nginx采用了分阶段资源分配技术,使得cpu与内存的占用率极低。
6.在高可用性上,nginx支持热部署,启动速度特别迅速,音系可以不间断服务的情况下,对软件版本或者配置进行升级。
启动前nginx的语法
[root@yao nginx-1.6.3]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax s ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is sucessful
启动nginx
[root@yao nginx-1.6.3]# /application/nginx/sbin/nginx
检查端口没被占用
[root@yao conf]# netstat -ano|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN off (0.00/0/0)
unix 3 [ ] STREAM CONNECTED 11680
检查nginx的服务端口是否启用
方法一
[root@yao nginx-1.6.3]# netstat -lnt | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
方法二
[root@yao nginx-1.6.3]# lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dhclient 909 root 5u IPv4 11196 0t0 UDP *:bootpc
master 1081 root 12u IPv4 11659 0t0 TCP localhost:smtp (LISTEN)
master 1081 root 13u IPv6 11661 0t0 TCP localhost:smtp (LISTEN)
sshd 1144 root 3u IPv4 12221 0t0 TCP 192.168.223.140:ssh->192.168.223.1:13816 (ESTABLISHED)
sshd 1706 root 3u IPv4 45580 0t0 TCP *:ssh (LISTEN)
sshd 1706 root 4u IPv6 45582 0t0 TCP *:ssh (LISTEN)
nginx 4031 root 6u IPv4 48204 0t0 TCP *:http (LISTEN)
nginx 4032 nginx 6u IPv4 48204 0t0 TCP *:http (LISTEN)
nginx.conf
[root@yao ~]# egrep -v "#|^$" /application/nginx/conf/nginx.conf.default
worker_processes 1; worker的进程数量
#事件区块
events { # 事件区块开始
worker_connections 1024; #每个worker进程支持的最大连接数量
}
http {
include mime.types; #nginx支持的媒体类型库文件
default_type application/octet-stream; #默认的媒体类型
sendfile on; #开启高效传输模式
keepalive_timeout 65; #连接超时
#独立的虚拟主机站点
server {
listen 80; #服务端口
server_name localhost; #提供域名的服务主机
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}