构建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、安装环境依赖包
2、下载Nginx并安装
Nginx安装成功!
四、Nginx虚拟主机的配置
在http下加入一行
在/usr/local/nginx/conf下新建vhosts.conf并添加以下内容。
在客户端配置hosts(C:\Windows\System32\drivers\etc\hosts)
1 | [root@nginx~] #yum-yinstallpcrepcre-develgccopenssl-devel |
1 2 3 4 5 6 7 8 9 10 11 | [root@nginx~] #wget |
Nginx安装成功!
四、Nginx虚拟主机的配置
1 | [root@nginxconf] #vim/usr/local/nginx/conf/nginx.conf |
1 | includevhosts.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] # |
相关文章推荐
- 构建Nginx服务器之一 安装及虚拟主机配置
- 构建基于Nginx的虚拟主机时异常:SIOCADDRT: File exists
- 基于nginx的单台服务器多站点的虚拟主机
- 在RHEL5下构建LAMP网站服务平台之编译安装Apache与配置基于域名的虚拟Web主机
- 构建基于Nginx的web服务器
- Nginx配置之基于域名的虚拟主机
- 基于nginx的虚拟主机的配置
- 构建基于Nginx的web服务器
- 构建LAMP平台利用虚拟主机实现提供discuz论坛、基于SSL安装phpMyAdmin、安装wordpress
- 构建SSL/TLS安全的基于域名的apache虚拟主机
- 构建FTP服务器,基于SSL,基于虚拟用户
- web服务器基于虚拟主机的三种配置
- 在Nginx中部署基于IP的虚拟主机
- Nginx配置之基于域名的虚拟主机
- 一块网卡绑定多个ip,在单一网卡服务器上运行多个基于ip的虚拟主机
- RHEL6.3配置Apache服务器(2) 构建虚拟主机
- 构建基于Nginx的web服务器
- Nginx搭建虚拟主机服务器
- 在linux下使用Nginx构建虚拟主机
- 构建httpd网站服务器(二) -- httpd服务的访问控制和基于域名、IP、端口的虚拟主机