基于域名的虚拟主机

创建站点目录

[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 虚拟主机的更多相关文章

  1. nginx虚拟主机配置

    nginx虚拟主机配置   虚拟主机的概念虚拟主机,就是把一台物理服务器划分成多个"虚拟"的服务器,每一个虚拟主机都可以有独立的域名和独立的目录nginx虚拟主机的配置nginx的 ...

  2. Apache与Nginx虚拟主机设置(多域名和多端口的区别)

    为了方便管理虚拟主机,应该尽量少修改主配置文件http.conf或者nginx.conf,大部分修改变更都在虚拟主机片配置文件httpd- vhost.conf或者vhost.conf中完成,这样有利 ...

  3. Nginx高性能服务器安装、配置、运维 (5) —— Nginx虚拟主机配置

    六.Nginx虚拟主机配置 建立基于域名的虚拟主机: (1)建立基于域名的虚拟主机配置文件(以abc.com为例): (2)更改虚拟主机配置文件: 更改配置如下(更改部分即可): server { l ...

  4. Nginx教程(二) Nginx虚拟主机配置

    Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...

  5. 配置Nginx虚拟主机

    实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基本环境 1. 安装nginx yum install -y epel-* yum isntall -y nginx vim 2. 建立虚机主 ...

  6. Nginx教程--02.Nginx虚拟主机的配置

    1.Nginx虚拟主机的配置 1.1 在conf目录下,使用命令 : vim nginx.conf 对上图解释: //全局区 worker _processes 1; //表示当前有1个工作的子进程, ...

  7. php管理nginx虚拟主机shell脚本

    使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考 代码如下 复制代码 #!/usr/bin/php -q& ...

  8. Nginx 虚拟主机 VirtualHost 配置

    Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在& ...

  9. Nginx虚拟主机配置教程

    说明:配置之前先把域名解析到服务器IP地址上 站点1:bbs.osyunwei.com  程序所在目录/data/osyunwei/bbs 站点2:sns.osyunwei.com  程序所在目录/d ...

  10. Linux(7)- Nginx.conf主配置文件、Nginx虚拟主机/访问日志/限制访问IP/错误页面优化、Nginx反向代理、Nginx负载均衡

    一.Nginx.conf主配置文件 Nginx主配置文件conf/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的.一般,每个区块以一对大括号{}来表示开始与结束. 核心模 ...

随机推荐

  1. Yocto开发笔记之《Makefile编写》(QQ交流群:519230208)

    开了一个交流群,欢迎爱好者和开发者一起交流,转载请注明出处. QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 =============================== ...

  2. nginx访问日志获取访问前10的url

    在ELK里面获取top10的url在日志量非常大的情况下是非常消耗内存的,所以写了一个脚本用来快速获取. 配置文件 log.conf [log] log_file = /data/logs/nginx ...

  3. PHP ob系列函数详解

    一. 相关函数简介:    1.Flush:刷新缓冲区的内容,输出.    函数格式:flush()    说明:这个函数经常使用,效率很高.    2.ob_start :打开输出缓冲区    函数 ...

  4. AppDelegate方法中文记录

    /// 在程序启动之后,重写自定义设置的位置 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOption ...

  5. <?xml version="1.0" encoding="utf-16"?>. use different encoding

    public string Serialize<T>(T serializeClass) { string xmlString = string.Empty; try { if (seri ...

  6. C-全局变量与局部变量

  7. CMD窗口如何调整大小 / 颜色

    Windows默认的命令行工具CMD暴丑无比..很多人都会因为这个原因去寻找漂亮的命令行工具.. 但是很多所谓的命令行工具并不能完美的支持到CMD.. 譬如 PowerCMD 或 Cmder 之流.. ...

  8. python内置函数每个执行一次

      open    #   with open('log','r') as f:    或者   r=open(filename,r+) with open ('1.txt','r',encoding ...

  9. select2搜索框查询加遍历

    <div class="form-group"> <label class="control-label col-sm-1 no-padding-rig ...

  10. motto1

    不要失去了才懂得珍惜.很多东西是不能再来的,又有很多东西再来是要付出代价的,所以,好好珍惜你现在拥有的一切,努力去争取你现在没有的.