nginx 虚拟主机
基于域名的虚拟主机
创建站点目录
[root@nginx conf]# cd /usr/local/nginx/html/
[root@nginx html]# pwd
/usr/local/nginx/html
[root@nginx html]# mkdir www
[root@nginx html]# mkdir blog
[root@nginx html]# mkdir bbs
[root@nginx html]# ls
50x.html bbs blog index.html www
修改nginx.conf
[root@nginx html]# cd /usr/local/nginx/conf/
server {
listen ;
server_name www.httpd.com; location /{
root html/www;
index index.html index.htm;
}
}
server {
listen ;
server_name blog.httpd.com; location /{
root html/blog;
index index.html index.htm;
}
}
server {
listen ;
server_name bbs.httpd.com; location /{
root html/bbs;
index index.html index.htm;
}
}
创建站点测试页、重启服务
[root@nginx conf]# echo "<h1>www.http.com</h1>" > /usr/local/nginx/html/www/index.html
<h1>www.http.com</h1> /usr/local/nginx/html/www/index.html
[root@nginx conf]# echo "<h1>bbs.http.com</h1>" > /usr/local/nginx/html/bbs/index.html
<h1>bbs.http.com</h1> /usr/local/nginx/html/bbs/index.html
[root@nginx conf]# echo "<h1>blog.http.com</h1>" > /usr/local/nginx/html/blog/index.html
<h1>blog.http.com</h1> /usr/local/nginx/html/blog/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]# /usr/local/nginx/sbin/nginx -s reload
添加本机hosts
[root@nginx bbs]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.161.134 www.httpd.com
192.168.161.134 bbs.httpd.com
192.168.161.134 blog.httpd.com
测试
[root@nginx bbs]# curl www.httpd.com
<h1>www.http.com</h1>
[root@nginx bbs]# curl bbs.httpd.com
<h1>bbs.http.com</h1>
[root@nginx bbs]# curl blog.httpd.com
<h1>blog.http.com</h1>
nginx 虚拟主机的更多相关文章
- nginx虚拟主机配置
nginx虚拟主机配置 虚拟主机的概念虚拟主机,就是把一台物理服务器划分成多个"虚拟"的服务器,每一个虚拟主机都可以有独立的域名和独立的目录nginx虚拟主机的配置nginx的 ...
- Apache与Nginx虚拟主机设置(多域名和多端口的区别)
为了方便管理虚拟主机,应该尽量少修改主配置文件http.conf或者nginx.conf,大部分修改变更都在虚拟主机片配置文件httpd- vhost.conf或者vhost.conf中完成,这样有利 ...
- Nginx高性能服务器安装、配置、运维 (5) —— Nginx虚拟主机配置
六.Nginx虚拟主机配置 建立基于域名的虚拟主机: (1)建立基于域名的虚拟主机配置文件(以abc.com为例): (2)更改虚拟主机配置文件: 更改配置如下(更改部分即可): server { l ...
- Nginx教程(二) Nginx虚拟主机配置
Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...
- 配置Nginx虚拟主机
实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基本环境 1. 安装nginx yum install -y epel-* yum isntall -y nginx vim 2. 建立虚机主 ...
- Nginx教程--02.Nginx虚拟主机的配置
1.Nginx虚拟主机的配置 1.1 在conf目录下,使用命令 : vim nginx.conf 对上图解释: //全局区 worker _processes 1; //表示当前有1个工作的子进程, ...
- php管理nginx虚拟主机shell脚本
使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考 代码如下 复制代码 #!/usr/bin/php -q& ...
- Nginx 虚拟主机 VirtualHost 配置
Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在& ...
- Nginx虚拟主机配置教程
说明:配置之前先把域名解析到服务器IP地址上 站点1:bbs.osyunwei.com 程序所在目录/data/osyunwei/bbs 站点2:sns.osyunwei.com 程序所在目录/d ...
- Linux(7)- Nginx.conf主配置文件、Nginx虚拟主机/访问日志/限制访问IP/错误页面优化、Nginx反向代理、Nginx负载均衡
一.Nginx.conf主配置文件 Nginx主配置文件conf/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的.一般,每个区块以一对大括号{}来表示开始与结束. 核心模 ...
随机推荐
- 零散的JavaScript公用方法
function stopBubble(e) { if (e && e.stopPropagation) {//如果传入了事件对象,那么就是非IE浏览器 e.stopPropagati ...
- mybatis报错Mapped Statements collection does not contain value for com.inter.IOper
首页 > 精品文库 > mybatis报错Mapped Statements collection does not contain value for com.inter.IOper m ...
- Objective-C学习笔记之for( int )机制
NSArray *myArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4&q ...
- php 数据访问(以mysql数据库为例)
//建一个连接,造一个连接对象$db = new MySQLi("localhost","root","123","mydb&qu ...
- 完整的ajax请求投票点赞功能的实现【数据库表一(票数)表二(ip限制重复投票)】
前端php页面 <?php if(isset($_GET['id'])){ $id=$_GET['id']; } include('data/conn.php'); $sqls="se ...
- vim的使用
vim的定位 home:光标移到行首 end:光标移到行尾 pageup:屏幕上翻页 pagedow:屏幕下翻页 shift+g:定位行 如转至10行 10shift+g shift+gg 转至 ...
- SQL 使用小记
1. case语句 示例 select id, name, case user_role then "管理员" then "未注册用户" then " ...
- 如何在ubuntu中启用SSH服务
如何在ubuntu14.04 中启用SSH服务 开篇科普: SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为 ...
- IIS Express 虚拟目录
1.打开C:\Users\<用户名>\Documents\IISExpress\config\applicationhost.config 2.编辑site节如下(行4) [html] v ...
- MyEclipse 中各种 libraries 的含义
MyEclipse 中各种 libraries 的含义 JRE System Library,Java EE 5 Libraries,Referenced Libraries这三个都是各 ...