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
Nginx配置简单基于域名的虚拟主机的更多相关文章
- Nginx配置之基于域名的虚拟主机
1.配置好DNS解析 大家好,今天我给大家讲解下在Linux系统下DNS服务器的基本架设,正向解析,反向解析,负载均衡,还有从域以及一个服务器两个域或者多个域的情况. 实验环境介绍:1.RHEL5.1 ...
- Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试
标签:Linux 域名 Nginx 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://xpleaf.blog.51cto.com/9 ...
- Nginx总结(四)基于域名的虚拟主机配置
前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的 ...
- •搭建LAMP环境及快速部署双网站并实现基于域名的虚拟主机
本节所讲内容: 实战:搭建LAMP环境及快速部署双网站并实现基于域名的虚拟主机 LAMP架构:??? Linux+Apache+Mysql+PHP Linux+Apache+Mysql/MariaDB ...
- nginx配置基于域名的虚拟主机
其实基于域名和基于ip的虚拟主机配置是差不多的,在配置基于ip的虚拟主机上我们只需要修改几个地方就能变成基于域名的虚拟主机,一个是要修改域名,一个是host文件直接看代码 [root@localhos ...
- nginx基于域名的虚拟主机配置(本地分布式项目域名配置及测试方法)
最有用的虚拟主机配置方式. 一个域名只能绑定一个ip地址,一个ip地址可以被多个域名绑定. 可以修改host文件实现域名访问. 前提:即使我们在nginx中配置基于域名的虚拟主机,也需要域名解析,即n ...
- 十八.搭建Nginx服务器、配置网页认证、基于域名的虚拟主机、ssl虚拟主机
配置要求: client:192.168.4.10 proxy:192.168.4.5(eth0) 192.168.2.5(eth1) web1:192.168.2.100 web2:192.168. ...
- 高级运维(二):搭建Nginx服务器、用户认证、基于域名的虚拟主机、SSL虚拟主机、Nginx反向代理
一.搭建Nginx服务器 目标: 在IP地址为192.168.4.5的主机上安装部署Nginx服务,并可以将Nginx服务器,要求编译时启用如下功能: 1> SSL加密功能 2> 设置Ng ...
- Nginx--服务部署、基于域名的虚拟主机配置
一.服务部署 1.预处理 安装CentOS ,配置hosts.静态IP.设置必要的安全参数等(略) 1-1.系统环境 [root@vnx ~]# cat /etc/redhat-release Cen ...
随机推荐
- 【Tomcat】虚拟主机
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDepl ...
- Spring 重定向(Redirect)指南
原文:Hacking the IntegerCache in Java 9? 链接:https://dzone.com/articles/hacking-the-integercache-in-jav ...
- nodejs express+nodemon 实现自动刷新 (热更新)
1.全局安装 nodemon npm i nodemon -g -f 2. 在项目中安装nodemon npm i nodemon -f 3.使用nodemon 在express项目中 运行nodem ...
- MySQL/MariaDB数据库的MHA实现高可用实战
MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...
- 【MySQL】FIND_IN_SET、LIKE、IN的区别
现在有张新闻表,里面有新闻名称name字段,有新闻类型type字段,1代表头条,2代表推荐,11代表热点,22代表最新,现在表中有两条记录,存储形式如下,现在的需求是查找头条新闻,及type中包含1的 ...
- 哈希长度拓展攻击之De1CTF - SSRF Me
题目考查:python代码审计.hash长度拓展攻击 0x01 题目源码: #! /usr/bin/env python #encoding=utf-8 from flask import Flask ...
- 《TensorFlow2深度学习》学习笔记(二)手动搭建并测试简单神经网络(附mnist.npz下载方式)
本实验使用了mnist.npz数据集,可以使用在线方式导入,但是我在下载过程中老是因为网络原因被打断,因此使用离线方式导入,离线包已传至github方便大家下载: https://github.com ...
- 如何为SUSE配置IP地址,网关和DNS
方法一.在命令行中配置.输入: ifconfig eht0 9.111.66.96 netmask 255.255.255.0 up route add default gw 9.111.66.1 方 ...
- 使用Xpath爬虫库下载诗词名句网的史书典籍类所有文章。
# 需要的库 from lxml import etree import requests # 请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows ...
- Dynamics 365 安装问题——无法访MSCRM_CONFIG数据库
1. 问题 2. 原因 出现此问题的一个或多个下列条件都为真︰ 在多务器中安装 Microsoft Dynamics 365.然后,直接在运行 Microsoft SQL Server 的服务器上 ...