您的位置:首页 > 运维架构 > Nginx

构建nginx服务器之一 基于虚拟主机

2016-10-31 14:26 337 查看
Nginx相对于Apache优点:1)高并发响应性能非常好,官方Nginx处理静态文件并发5w/s2)反向代理性能非常强。(可用于负载均衡)3)内存和cpu占用率低。(为Apache的1/5-1/10)4)对后端服务有健康检查功能。5)支持PHPcgi方式和fastcgi方式。6)配置代码简洁且容易上手。三、Nginx的安装1、安装环境依赖包
1
[root@nginx~]
#yum-yinstallpcrepcre-develgccopenssl-devel

2、下载Nginx并安装
1
2
3
4
5
6
7
8
9
10
11
[root@nginx~]
#wget'target='_blank'>http://nginx.org/download/nginx-1.6.3.tar.gz[/code]
[root@nginx~]
#tar-zxfnginx-1.6.3.tar.gz

[root@nginx~]
#cdnginx-1.6.3

[root@nginxnginx-1.6.3]
#./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module

[root@nginx~]
#make&&makeinstall

[root@nginxnginx-1.6.3]
#/usr/local/nginx/sbin/nginx##启动Nginx

[root@nginxnginx-1.6.3]
#ps-ef|grepnginx

root44321022:12?00:00:00nginx:masterprocess
/usr/local/nginx/sbin/nginx

nobody44334432022:12?00:00:00nginx:workerprocess

root44372037022:12pts
/2
00:00:00
grep
nginx

[root@nginxnginx-1.6.3]
#



Nginx安装成功!
四、Nginx虚拟主机的配置
1
[root@nginxconf]
#vim/usr/local/nginx/conf/nginx.conf

在http下加入一行
1
includevhosts.conf;

在/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@nginxconf]
#catvhosts.conf

server{

listen80;

server_namewww.a.com;


location/{

root
/usr/local/nginx/html/a
;

indexindex.htmlindex.htm;

}

}


server{

listen80;

server_namewww.b.com;


location/{

root
/usr/local/nginx/html/b
;

indexindex.htmlindex.htm;

}

}


server{

listen80;

server_namewww.c.com;


location/{

root
/usr/local/nginx/html/c
;

indexindex.htmlindex.htm;

}

}

[root@nginx~]
#cd/usr/local/nginx/html/

[root@nginxhtml]
#mkdir{a,b,c}

[root@nginxhtml]
#echoaaaaaa>a/index.html

[root@nginxhtml]
#echobbbbbb>b/index.html

[root@nginxhtml]
#echocccccc>c/index.html

[root@nginxconf]
#/usr/local/nginx/sbin/nginx-t

nginx:theconfiguration
file
/usr/local/nginx/conf/nginx
.confsyntaxisok

nginx:configuration
file
/usr/local/nginx/conf/nginx
.conf
test
issuccessful

[root@nginxconf]
#

[root@nginxconf]
#/usr/local/nginx/sbin/nginx-sreload

[root@nginxconf]
#

在客户端配置hosts(C:\Windows\System32\drivers\etc\hosts)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息