Nginx相对于Apache优点:
1) 高并发响应性能非常好,官方Nginx处理静态文件并发5w/s
2) 反向代理性能非常强。(可用于负载均衡)
3) 内存和cpu占用率低。(为Apache的1/5-1/10)
4) 对后端服务有健康检查功能。
5) 支持PHP cgi方式和fastcgi方式。
6) 配置代码简洁且容易上手。
三、Nginx的安装
1、安装环境依赖包
1 | [root@nginx ~] # yum -y install pcre pcre-devel gcc openssl-devel
|
2、下载Nginx并安装
1 2 3 4 5 6 7 8 9 10 11 | [root@nginx ~] # wget http://nginx.org/download/nginx-1.6.3.tar.gz
[root@nginx ~] # tar -zxf nginx-1.6.3.tar.gz
[root@nginx ~] # cd nginx-1.6.3
[root@nginx nginx-1.6.3] # ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@nginx ~] #make && make install
[root@nginx nginx-1.6.3] #/usr/local/nginx/sbin/nginx ##启动Nginx
[root@nginx nginx-1.6.3] # ps -ef | grepnginx
root 4432 1 0 22:12 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 4433 4432 0 22:12 ? 00:00:00 nginx: worker process
root 4437 2037 0 22:12 pts /2 00:00:00 grep nginx
[root@nginx nginx-1.6.3] #
|

Nginx安装成功!
四、Nginx虚拟主机的配置
1 | [root@nginx conf] # vim/usr/local/nginx/conf/nginx.conf
|
在http下加入一行
在/usr/local/nginx/conf下新建vhosts.conf并添加以下内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | [root@nginx conf] # cat vhosts.conf
server {
listen 80;
server_name www.a.com;
location / {
root /usr/local/nginx/html/a ;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.b.com;
location / {
root /usr/local/nginx/html/b ;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.c.com;
location / {
root /usr/local/nginx/html/c ;
index index.html index.htm;
}
}
[root@nginx ~] # cd /usr/local/nginx/html/
[root@nginx html] # mkdir {a,b,c}
[root@nginx html] # echo aaaaaa > a/index.html
[root@nginx html] # echo bbbbbb >b/index.html
[root@nginx html] # echo cccccc >c/index.html
[root@nginx conf] #/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@nginx conf] #
[root@nginx conf] #/usr/local/nginx/sbin/nginx -s reload
[root@nginx conf] #
|
在客户端配置hosts(C:\Windows\System32\drivers\etc\hosts)
转载于:https://blog.51cto.com/zhangbin666/1867647