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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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的左外连接