域名
域名(英语:Domain Name),又称网域,是由一串用点分隔的名字组成的Internet上某一台计算机或计算机组的名称,用于在数据传输时对计算机的定位标识。
顶级域名(一级域名):
◇ 按国家划分:cn、tw(台湾)、hk(香港)等。cn表示中国,tw表示台湾,hk表示香港。
◇ 按组织性质划分:org、net、com、edu、gov、cc等。com表示company,给企业用。edu表示education,给大学用。org表示organization,给非盈利组织用。
◇ 反向域:.arpa。这是反向解析的特殊顶级域。
更多一级域名:https://baike.baidu.com/item/%E5%9F%9F%E5%90%8D/86062?fr=aladdin#5_1
www.baidu.com,www是三级域名,baidu是二级域名,com是一级域名。参考《计算机网络(第7版)-谢希仁》https://blog.csdn.net/chayangdz/article/details/95178164
屏蔽IP,暴露域名
网关可以统一对外暴露的IP和Port。
本地实验时,host文件中可以映射IP和域名,可以改暴露IP为暴露域名。
Windows下的hosts文件地址:C:/Windows/System32/drivers/etc/hosts
Linux下的hosts文件所在路径: /etc/hosts
直接加上一行IP 域名即可,如:
127.0.0.1 www.hao.com
修改hosts文件推荐SwitchHosts这个工具。
广域网上,DNS(Domain Name System)服务器负责域名解析。查看和配置DNS服务器IP:https://jingyan.baidu.com/article/6181c3e06bc70e152ef153b9.html
解析域名,先走hosts文件,找不到再走DNS,如果配置了DNS就走配置的,如果没配置,走自动的,也就是接入的网络运营商的DNS,如北京电信的DNS等。 https://blog.csdn.net/u010559460/article/details/87903745
默认端口
http默认端口是80,https默认端口是443。(默认端口号:https://blog.csdn.net/ypt523/article/details/79636647)
访问https://www.baidu.com/就是在访问https://www.baidu.com:443 ,访问http://www.baidu.com:80 就是在访问http://www.baidu.com:80
一个域名可以对应多个IP,即动态IP,如www.baidu.com对应多个IP,即对应多个服务器。
Nginx
多个域名可以对应一个IP。多个域名映射到同一个Nginx服务器,然后Nginx服务器代理这些域名对应的负责处理请求的服务器(动态代理:代理多个)(反向代理:代理服务器)。也就是转发请求,实现路由功能。
nginx可以通过命令行来启动,操作命令:
-
启动:
start nginx.exe
-
停止:
nginx.exe -s stop
-
重新加载:
nginx.exe -s reload
nginx程序包/conf/nginx.conf关键内容分析:
访问http://mange.leyou.com会转发到http://127.0.0.1:9001
完整配置举例:
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name manage.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:9001;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
server {
listen 80;
server_name api.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:10010;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
}