Nginx配置简单基于域名的虚拟主机

首先修改hosts文件,让浏览器在看到a.com或是www.a.com的网址时知道上哪里去找:

复制代码
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost
127.0.0.1 a.com
127.0.0.1 www.a.com
复制代码

打开nginx.conf,写入下面两段:

复制代码
    server {
        listen       7777;
        server_name  a.com;

        location / {
            root   html/7777;
            index  index.html index.htm;
        }
    }
    
    server {
        listen       9999;
        server_name  a.com;

        location / {
            root   html/9999;
            index  index.html index.htm;
        }
    }
复制代码

然后,在C:\nginx-1.16.1\html创建目录7777,9999,把index.html 拷贝进去,然后修改得能区分开来:

复制代码
<!DOCTYPE html>
<html>
<head>
<title>Welcome to 7777</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to 7777</h1>
</html>
复制代码
复制代码
<!DOCTYPE html>
<html>
<head>
<title>Welcome to 9999</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to 9999</h1>
</html>
复制代码

之后,平滑重启nginx

C:\nginx-1.16.1>nginx.exe -s reload

之后在浏览器器里就能看效果了:

--END-- 2019年12月14日08:22:02

posted @   逆火狂飙  阅读(169)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2014-12-14 【Canvas与艺术】绘制黑白山间野营Camping徽章
2014-12-14 MySQL的左外连接
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东
点击右上角即可分享
微信分享提示