最近买了台DELL R620服务器,配了Xeon E5-2670V2,物理核心20核逻辑核心40核,再加了32G内存,本来想着高配置服务器美滋滋,,直到要玩起来才发现很麻烦。在此总结以下:
1.首先需要公网ip
虽然说申请有些困难,但也是看运营商和地区而定的。像什么广电,移动基本别想了,广电的打电话过去甚至不知道公网ip是什么。移动众所周知老无赖一个,哪有那么容易给你吃白食?你如果想在移动申请公网ip,先准备好2w块人民币~所以,联通和电信申请是最容易的。可以尝试一下联系客服给你开,不行工信部走起。我会另外写一下我是怎么申请到的,希望对大家有启发
2.DDNS
有了公网ip就可以了吗?想peach。公网ip又分固定公网ip和动态公网ip,固定公网ip是专门给企业或者有关部门使用的,但如果你有钱可以申请,一个月的价格比一年千兆宽带贵的多(看地区而定),而且固定公网ip的80端口和443端口较容易开,如果你有固定公网ip,绝对省事。
但是呢,像我们这些穷人,又爱折腾,当然只给动态公网ip了。动态ip是什么?就是说在一定的触发条件下公网ip会变动,有可能是48小时自动变ip,或者是你重启电脑,重启路由器就变ip。一般ip变动的值都是最后一部分,例如xxx.xxx.xxx.123,这个公网ip后面的123不是固定的,会在0-255之间变动。这就非常阴间了,是个人都知道,域名解析A记录必须解析一个固定的公网ip,总不可能我们不停手动去改ip,要是什么时候ip变了,假设那时候我们在拉屎,拉了一个小时,我们没有及时发现,网站也就宕机了一个小时,影响非常大。
所以呢,出现了这样一个东西,叫做DDNS,第一个D意为“动”,也就是动态的意思。组合起来,就是动态DNS。这个东西的原理是什么呢?他能够实时监测ip的变动,一旦监测ip变动,就会将域名的解析记录修改为新分配的公网ip。这是一个非常不错的玩意。在许多路由器都会带上这个设置,命名为DDNS或动态DNS,但是有些路由器只有第三方DDNS服务,例如花生壳,第三方DDNS非常慢,无法将家宽优势发挥出来。所以我们可以尝试给路由器刷第三方固件,有些固件会有阿里云或者DNSpod的DDNS服务,这样就方便很多。但是如果有懒得弄的大佬,或者路由器是老古董,那就要自己写一个定时运行的DDNS脚本来监测了,这个会在下面的文章讲到。
3.端口转发
这下公网ip解决了,然而只是解决了一个棘手的问题罢了。我们还要设置端口转发。虽然我们有了公网ip,但是你可以尝试一下,访问一下宝塔面板,ip+8888,你仍然是访问不了的。这是因为路由器设置,我们的端口仍然是不对外的。所以我们要在路由器配置端口转发,将外网的访问请求转到对应的内部端口,这样才能正常访问
4.域名后端口省略处理
如果配置正常,你应该是可以访问宝塔面板了,但是当你兴致勃勃的新建了一个网站,并尝试访问时,wtf,访问超时?哦霍,忘记说了,现在所有运营商都会封锁80,8080,443等敏感端口,就是为了防止家宽建站。(当然有些地方可能不会封443端口,这个可以尝试一下),无论你怎么尝试端口转发,都是不行的。这下就麻烦了,那建站有个p用啊~~~
但是,你的域名此时并不是无法访问。既然80,443端口废掉了,我们可以换其他的端口呀。比如说2233,你看这个端口多有味道,我们只要在宝塔面板将你的网站端口从80更改成2233,就可以访问你的网站了。只不过呢,你需要在你的域名后面加个端口号,例如http://yourdomain.com:2233,这样才能够正常访问。这就是没有80端口或者443端口的弊端:需要加上个端口——这不仅对用户不友好(因为有时会有用户分不清中文的冒号和英文的冒号),最要命的是,搜索引擎的蜘蛛看到这么奇怪的域名,都不来了。那为什么80端口和443端口的网站不用在域名后面手动加端口呢,实际上无论端口是多少,域名后面的端口都是存在的,只不过浏览器已经帮你省略80和443端口了。然而如果不是80或者443端口的话,浏览器是不会帮你的,只能靠你自己。
为了节省大量的麻烦(主要是域名后面加端口实在是不好看),我们需要通过其他手段去掉域名后面的端口号,这样即使我使用非80或443端口建站,直接输入域名也能正常访问网站,无需再手动输入端口,达到和80端口443端口网站一样的访问效果。
针对端口号这个问题,我目前找到两种的针对方法。第一种:cdn,众所周知,有些cdn的回源可以设置自定义端口,用cdn可以解决去掉端口号的问题,这个方法同时适用于域名未备案的网站(使用香港cdn),缺点就是不能直接回源,非境内cdn会对速度有一定影响;第二种就是隐性url解析,需要你的网站域名添加多一个中转域名用作解析,而这个中转域名带端口号访问,只要把我们正式的网站域名解析到我们的中转域名,再配上隐性url解析记录,就可以实现无端口号访问网站。优点不用说,直接回源;而缺点吗,就是需要备案的域名,并且需要购买高级的解析套餐。在阿里云我不确定隐性url这种记录在免费版云解析有没有,我用的是企业版云解析,14块一个月。
可能看的不是很明白,我举个例子:
我要建一个网站,域名为123.com,主机ip为11.11.11.11,然而没有80和443端口,将123.com解析到11.11.11.11后,我只能将网站端口更改为6666,这样用户访问网站时,只能输入123.com:6666来访问我的网站。为了让用户能够直接输入123.com来访问我的网站,我需要这样做:
首先,我新建了一个域名,叫做888.com,我将它解析到11.11.11.11,这样的话当我输入888.com:6666时,也能访问到和123.com:6666一样的页面。
然后,我修改123.com的解析记录,我将原来的A记录删除,然后将123.com解析到888.com:6666(这种解析记录是隐性url解析),这样的话,当我访问123.com时,也就相当于访问了888.com:6666,而888.com解析到源站的ip,即11.11.11.11。所以,我就完美实现了通过直接访问123.com正常回源。
这就是隐性url解析,当然,前提需要域名已经备案。
但是:隐性url有一个很大很大,甚至是致命的问题,首先,隐性url解析是基于iframe实现的,这对搜索引擎的蜘蛛非常不友好,注重seo的兄弟千万不能使用,第二,在浏览器中显示的域名永远都是隐性url记录的解析值,无论你怎么点内部链接,浏览器永远就显示那个域名,用户看了会摸不着头脑。可以这样理解:我建个博客,域名为123.com,使用了隐性url解析,我打开一篇文章,发现url还是原来的123.com,大受震撼。我登陆wordpress后台,url输入123.com/wp-admin,(刻进DNA的链接),发现页面正常跳转,但是浏览器显示的url还是原来的123.com???有用户看到的话,绝对以为闹鬼了。那么蜘蛛要来爬你的站,发现一个域名指向了一堆不同的页面,你让他怎么想?它还会来爬吗?
所以,非常不推荐使用隐性url,有能力最好使用cdn~~
但是呢,cdn也不是完美的。国内除开要备案不说,有可能还会被有关部门发现,家宽建站会被勒令停止。用了香港cdn不同,你爱咋弄就咋弄了,但是也要小心运营商对http请求的监管!在网上会看到有大佬吐槽家宽建站有时会掉线(宕机),典型的被发现了
然后再说一句,完全不需要在你的服务器上弄什么反向代理啊,重定向什么的,外网80端口的请求早就在没有到达服务器之前就被拦截了,根本就没有流量进去,弄了也是白弄。内网里端口畅通无阻,爱咋发咋发,去到外网给你一锤,别想进来!
这就是我们在家里建站必须解决的所有问题了,无论怎么样,都没有什么计划是能完全媲美去阿里云买一个云服务器建站的。如果是像我一样喜欢折腾,鼓捣的大佬可以往下看,我给出了详细的操作方法供你参考;但是如果你只是图新鲜,正准备这样玩的;或者说完全没有意识到这项工作难度的兄弟,建议还是好好使用云服务器,撇开搭建难度不说,稳定性相信应该不会比云服务商家好,家里停电怎么办?不仅如此,还要购置实体服务器,树莓派或者小主机,再加上国内cdn费用等等,更别说要耗费大量时间了。各位站长只需做好自己的网站即可,不必要过于折腾在家搭服务器,虽说实体服务器的配置自由,家宽大,有个千把两千块钱能配个64核几百G内存十多T的SSD,再加千兆宽带,上下行100M,要是放在阿里云或腾讯云卖得十多万一个月。也许到时你会发现,这钱还不如买台云服务器。追求稳定,速度的站长,去买云服务器即可!
P.S.没有公网ip的大佬,或者不想搞这么多幺蛾子的兄弟,还有一个方法,就是内网穿透。内网穿透几乎可以解决以上所有的难题,但正如开头所说,速度限制较大,第三方内网穿透的速度更是不敢恭维(提供部分较知名的内网穿透服务商:nat123,花生壳,sakura frp,freefrp等等),若是有闲置大带宽云服务器的兄弟也可以自己搭建frp服务,我到时也会写教程。可我是这样想的,既然有云服务器了,何必不用云服务器呢~
高能警告!这是最后的提醒,请各位大佬站长仔细斟酌,三思而后行!折腾党欢迎~
本文是针对动态公网ip,域名没备案,80端口和443端口被封的家用服务器的教程,如果您的域名已经备案,或者没有公网ip,请拉到本文末尾,查看我写的其他文章,里面也从0开始进行讲解,会针对其他情况提供更加可行多元化的方案,欢迎阅读
rosmontis.com/archives/1798
正文开始
1.准备物理设备
可以是机架式服务器,塔式服务器,工程机,tb的centos小主机甚至你家的电脑等等,如果是搭网站,24小时开机的觉悟一定要有,噪音,电费等事宜自己要解决,不行的话可以去买云服务器了,没必要这么折腾
各位可以看看我的,花了很多钱,(其实还不如去腾讯云秒杀一台服务器)
数数装了几根内存,就装内存的的钱也够买一年服务器了(⊙o⊙)
2.自行申请公网ip
3.安装系统,配置环境
我是觉得,高端的服务器要配置最好用的面板-宝塔(不打广告啊)
4.DDNS配置(请根据自身服务器环境进行配置)
我的服务器使用宝塔面板
首先访问内网宝塔面板,因为现在没有配置公网ip,所以是访问不了的
DDNS服务即为动态解析,在监测到服务器ip变动后能够自动修改域名解析值,保证域名正常访问,免除许多麻烦。
因为我的域名是在阿里云注册的,所以我通过阿里云DNS的API实现自动DDNS
在DNSpod也有类似功能,这里不再过多赘述
(1)阿里云设置域名解析
直接去阿里云的云解析控制台,添加一个域名解析记录,值随便写,便于到时候判断ddns服务是否生效
(2)安装阿里云SDK(Python环境,阿里云也提供了其他语言,可以自行查看官方文档)
回到宝塔,连接ssh,输入以下命令检查系统是否安装了python
[root@localhost ~]# python
若提示未找到命令,请执行下面这条
[root@localhost ~]# python3
从这张图可以看到,我的服务器安装了python3.6.8,所以我不用另外安装了
要是两个命令都是报错的话,请自行安装python(可以在宝塔应用商店找到Python项目管理器,里面一键安装)
没有报错的话,我们直接安装阿里的SDK了,依次执行以下命令:
Python3.0以下版本或pip3.0以下版本请使用以下命令:
安装阿里云核心SDK库
pip install aliyun-python-sdk-core
安装阿里云域名SDK库
pip install aliyun-python-sdk-domain
安装阿里云DNS-SDK库
pip install aliyun-python-sdk-alidns
Python3.0及以上版本请使用以下命令:
安装阿里云核心SDK库
pip3 install aliyun-python-sdk-core
安装阿里云域名SDK库
pip3 install aliyun-python-sdk-domain
安装阿里云DNS-SDK库
pip3 install aliyun-python-sdk-alidns
没碰过python或者够懒的兄弟直接把上面的都复制下来执行一遍就行了,反正注释会省略的
没有报错就差不多了
若是出现以下报错:
=============================DEBUG ASSISTANCE=============================
If you are seeing a compilation error please try the following steps to
successfully install cryptography:
1) Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
=============================DEBUG ASSISTANCE=============================
请升级pip版本,执行命令:
pip3 install –upgrade pip
(3)代码实现与配置
好,这下基本安装完python环境了,来,开始写(抄)DDNS代码:
新建一个空白文件,命名为ddns.py,代码复制起来:
!/usr/bin/env python3
coding=utf-8
加载核心SDK
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
加载获取 、 新增、 更新、 删除接口
from aliyunsdkalidns.request.v20150109 import DescribeSubDomainRecordsRequest, AddDomainRecordRequest, UpdateDomainRecordRequest, DeleteDomainRecordRequest
加载内置模块
import json,urllib
AccessKey 和 Secret 建议使用 RAM 子账户的 KEY 和 SECRET 增加安全性
ID = ‘你的AccessKey’
SECRET = ‘你的Secret’
地区节点 可选地区取决于你的阿里云帐号等级,普通用户只有四个,分别是杭州、上海、深圳、河北,具体参考官网API
regionId = ‘cn-hangzhou’
配置认证信息
client = AcsClient(ID, SECRET, regionId)
设置主域名
DomainName = ‘你的根域名’
子域名列表 列表参数可根据实际需求增加或减少值
SubDomainList = [‘二级域名’]
获取外网IP 三个地址返回的ip地址格式各不相同,3322 的是最纯净的格式, 备选1为 json格式 备选2 为curl方式获取 两个备选地址都需要对获取值作进一步处理才能使用
def getIp():
# 备选地址: 1, http://pv.sohu.com/cityjson?ie=utf-8 2,curl -L tool.lu/ip
with urllib.request.urlopen(‘http://www.3322.org/dyndns/getip’) as response:
html = response.read()
ip = str(html, encoding=’utf-8′).replace(“\n”, “”)
return ip
查询记录
def getDomainInfo(SubDomain):
request = DescribeSubDomainRecordsRequest.DescribeSubDomainRecordsRequest()
request.set_accept_format(‘json’)
# 设置要查询的记录类型为 A记录 官网支持A / CNAME / MX / AAAA / TXT / NS / SRV / CAA / URL隐性(显性)转发 如果有需要可将该值配置为参数传入
request.set_Type(“A”)
# 指定查记的域名 格式为 ‘test.example.com’
request.set_SubDomain(SubDomain)
response = client.do_action_with_exception(request)
response = str(response, encoding=’utf-8′)
# 将获取到的记录转换成json对象并返回
return json.loads(response)
新增记录 (默认都设置为A记录,通过配置set_Type可设置为其他记录)
def addDomainRecord(client,value,rr,domainname):
request = AddDomainRecordRequest.AddDomainRecordRequest()
request.set_accept_format(‘json’)
# request.set_Priority(‘1’) # MX 记录时的必选参数
request.set_TTL(’60’) # 可选值的范围取决于你的阿里云账户等级,免费版为 600 – 86400 单位为秒
request.set_Value(value) # 新增的 ip 地址
request.set_Type(‘A’) # 记录类型
request.set_RR(rr) # 子域名名称
request.set_DomainName(domainname) #主域名
# 获取记录信息,返回信息中包含 TotalCount 字段,表示获取到的记录条数 0 表示没有记录, 其他数字为多少表示有多少条相同记录,正常有记录的值应该为1,如果值大于1则应该检查是不是重复添加了相同的记录
response = client.do_action_with_exception(request)
response = str(response, encoding=’utf-8′)
relsult = json.loads(response)
return relsult
更新记录
def updateDomainRecord(client,value,rr,record_id):
request = UpdateDomainRecordRequest.UpdateDomainRecordRequest()
request.set_accept_format(‘json’)
# request.set_Priority(‘1’)
request.set_TTL(’60’)
request.set_Value(value) # 新的ip地址
request.set_Type(‘A’)
request.set_RR(rr)
request.set_RecordId(record_id) # 更新记录需要指定 record_id ,该字段为记录的唯一标识,可以在获取方法的返回信息中得到该字段的值
response = client.do_action_with_exception(request)
response = str(response, encoding=’utf-8′)
return response
删除记录
def delDomainRecord(client,subdomain):
info = getDomainInfo(subdomain)
if info[‘TotalCount’] == 0:
print(‘没有相关的记录信息,删除失败!’)
elif info[“TotalCount”] == 1:
print(‘准备删除记录’)
request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
request.set_accept_format(‘json’)
record_id = info["DomainRecords"]["Record"][0]["RecordId"]
request.set_RecordId(record_id) # 删除记录需要指定 record_id ,该字段为记录的唯一标识,可以在获取方法的返回信息中得到该字段的值
result = client.do_action_with_exception(request)
print('删除成功,返回信息:')
print(result)
else:
# 正常不应该有多条相同的记录,如果存在这种情况,应该手动去网站检查核实是否有操作失误
print(“存在多个相同子域名解析记录值,请核查后再操作!”)
有记录则更新,没有记录则新增
def setDomainRecord(client,value,rr,domainname):
info = getDomainInfo(rr + ‘.’ + domainname)
if info[‘TotalCount’] == 0:
print(‘准备添加新记录’)
add_result = addDomainRecord(client,value,rr,domainname)
print(add_result)
elif info[“TotalCount”] == 1:
print(‘准备更新已有记录’)
record_id = info[“DomainRecords”][“Record”][0][“RecordId”]
cur_ip = getIp()
old_ip = info[“DomainRecords”][“Record”][0][“Value”]
if cur_ip == old_ip:
print (“新ip与原ip相同,无法更新!”)
else:
update_result = updateDomainRecord(client,value,rr,record_id)
print(‘更新成功,返回信息:’)
print(update_result)
else:
# 正常不应该有多条相同的记录,如果存在这种情况,应该手动去网站检查核实是否有操作失误
print(“存在多个相同子域名解析记录值,请核查删除后再操作!”)
IP = getIp()
循环子域名列表进行批量操作
for x in SubDomainList:
setDomainRecord(client,IP,x,DomainName)
删除记录测试
delDomainRecord(client,’b.jsoner.com’)
新增或更新记录测试
setDomainRecord(client,’192.168.3.222′,’a’,DomainName)
获取记录测试
print (getDomainInfo(DomainName, ‘y’))
批量获取记录测试
for x in SubDomainList:
print (getDomainInfo(DomainName, x))
获取外网ip地址测试
print (‘(‘ + getIp() + ‘)’)
太长了看不过来的话,这里针对个人情况指出需要修改文件几个地方:
AccessKey 和 Secret 建议使用 RAM 子账户的 KEY 和 SECRET 增加安全性 ID = ‘你的AccessKey’ SECRET = ‘你的Secret’
这些AccessKey和Secret想必各位都能找到ヾ(≧▽≦*)o
为了保证信息安全,建议使用子账户的AccessKey和Secret,并且手动修改子账户的权限
设置主域名 DomainName = ‘你的根域名’ # 子域名列表 列表参数可根据实际需求增加或减少值 SubDomainList = [‘二级域名’]
那么这个也是需要注意的, DomainName要填你的根域名,例如123.com
那如果我要填a.123.com怎么办? SubDomainList就填你的二级域名,但不要带上你的根域名!譬如a.123.com,你只需要填a就可以了
注意,这个动态DDNS,并不局限于一个子域名,如果你有多个子域名需要使用动态DDNS,例如a.123.com和b.123.com,可以在 SubDomainList 里直接填写a和b,二级域名之间使用逗号隔开
例:
设置主域名 DomainName = ‘123.com’ # 子域名列表 列表参数可根据实际需求增加或减少值 SubDomainList = [‘a,b’] # 这样就是配置了a.123.com和b.123.com使用动态DDNS
还有一个:
request.set_TTL(’60’) # 可选值的范围取决于你的阿里云账户等级,免费版为 600 – 86400 单位为秒
这个就是TTL,开了企业版解析套餐的土豪可以调整一下这个,不用白不用,记录生效也快嘛,60就是一分钟,600就是十分钟,自己调就行了
编辑完之后保存文件,转到ssh,先测试一下api能否正常调用,输入命令:
python3.0(含)以上版本用下面这个 python3 /文件具体路径/ddns.py #python3.0以下版本用下面这个 python /文件具体路径/ddns.py #例 #python3 /www/ddns.py
返回信息若为以下提示,说明配置成功
★[2022-01-10 00:55:02] Successful —————————————————————————- 准备更新已有记录 新ip与原ip相同,无法更新! —————————————————————————- ★[2022-01-10 00:56:02] Successful —————————————————————————- 准备更新已有记录 更新成功,返回信息: {“RequestId”:”xxxxxxxxxxxxxxxxxxxxxx”,”RecordId”:”xxxxxxxxxxxxxxxxxxxxxx”} —————————————————————————-
我们去到阿里云云解析页面,若看到域名记录值发生变化,说明api修改成功,DDNS基本配置完成!
(4)添加定时任务,自动监测公网ip变化
转到宝塔面板-计划任务,添加shell脚本任务:
脚本内容就是刚刚ddns.py的执行命令,例:python3 /www/ddns.py
执行周期按需填写,建议两分钟执行一次,我选择一分钟的监测频率,这样当公网ip变动后,可以缩短宕机恢复时间;
我们也可以同时创建多个计划任务,最大程度监测公网ip变化,保证网站正常运行
任务创建好后要手动执行一下,检查日志,没有报错就可以了
恭喜,你现在完成了万里长征第一步,喜提动态DDNS服务一个!
5.端口转发实现真正意义上的外网访问
单是有公网ip还是不行的,不信?你可以试试用公网ip访问宝塔面板,我敢肯定绝对是访问超时,更别说搭建网站了。
这是因为我们路由器的设置还是对外封锁端口,导致无法访问到我们的服务器。要解决这个问题,我们需要登录路由器管理页面配置端口转发,将外网用户对服务器的请求转发到内网所对应的服务器,这样就可以从外网正常访问我们的服务器了。
废话不多说,先访问服务器的管理页面,大部分的路由器管理页面地址是192.168.0.1或192.168.1.1
输入管理员密码即可成功进入后台,忘记密码请reset路由器配置
(该设置的位置及名称因路由器品牌和型号而异,请加以分辨)
找到转发规则,虚拟服务器,添加端口转发规则
我们直接添加新条目,先尝试转发宝塔面板的入口
注意:服务端口号是可以随意填的,路由器会将服务端口的请求转发到内部端口,外网用户通过公网ip+服务端口即可访问到内部端口,但是像80,443,8080这类端口就没辙
举个例子:宝塔面板默认端口为8888,如果你的服务端口号和内部端口号都是填写8888,那么你直接输入公网ip+8888就能访问宝塔面板。
如果你的服务端口填了1234,那么你输入公网ip+8888会访问超时,只有输入公网ip+1234才会访问到宝塔面板~
(相当于一个奇怪的内网穿透)
ip地址填写宝塔面板内网ip,保存
现在尝试通过公网ip+服务端口访问宝塔面板入口,若能够成功访问,说明配置成功
若是上面的宝塔面板端口转发配置成功,接下来便需要转发网站的端口,让我们搭建的网站可以通过指定的端口被外网访问
登录宝塔面板,创建一个网站,网址最好已经配置DDNS,便于检验端口转发是否成功
创建完成后,点击站点设置,手动添加域名
因为80端口和443端口已经被运营商封锁,我们需要为网站分配其他的端口。如上图,我给我的网站分配了5555端口
实现:添加域名<127.0.0.1:自定义端口>,端口你随便填可以了,11451也可以,就是臭了点
添加完成后,注意要去防火墙放行
然后呢,就去路由器管理页面配置端口转发:
ip地址还是填宝塔面板内网地址即可
然后,我们需要验证一下端口转发是否正常工作:
(1)公网ip+服务端口
(2)已配置DDNS的网址+服务端口(优先验证这个)
像我刚刚使用了5555端口创建网站,我就访问< 公网ip:5555 >或< 已配置DDNS的网址:5555 >检查能否正常从外网访问,用多几个设备检查( •̀ ω •́ )✧
如下图,访问不超时就是成功
至此,端口转发已经配置完成
P.S.我在撰写这篇文章的时候,有一个想法,是否可以将非80和443的服务端口转发到内网的80端口呢?例如,外网访问1111端口,就能直接转发到内网80端口。虽然运营商封了外网的80和443,但是内网没有啊!这样就可以省掉更改网站运行端口这一步骤。但是似乎也有一个bug:如果我运行多个网站呢?全都转发到80端口吗?有待验证,有兴趣的大佬可以尝试一下
6.解决访问网站时域名后面要加端口号的问题
(去掉难看的端口号,艸,这破端口看得人烦)
运营商封掉了美妙的80和443端口,只留下一堆奇奇怪怪的端口,让我们在访问域名的时候都要带上个小尾巴,非常恶心,如果是自己用的网站可以理解,但是,爷靠着他赚钱呢!搜索引擎看见这么奇怪的域名,都懒得来爬,这不玩完了吗?用户本来输了个域名就可以访问的网站,现在偏偏要加个端口,你说烦不烦?再说,中文的:和英文的:(冒号)超级难分,用户手骉怎么办?不用玩了呐!所以,一个合格的站长,不能忍受这种问题的存在,既然已经走到这一步,那就让暴风雨来的更猛烈些吧~
注意:本篇文章将针对已备案的域名,提供解决访问网站时域名后面要加端口号的步骤,若你的域名未备案,请拉到本文末尾,查看另外那篇针对未备案域名提供解决方案的文章,感谢您的支持~
由于我们的域名备案了,此时我们有两个选择:第一个是使用第三方CDN帮助我们实现去掉端口的问题,;第二个就是使用隐性url解析帮我们隐藏掉原来带端口的访问域名
不过在我们开始操作之前,还有一个步骤不能忽略:我们要一个中转的域名
解释一下:由于我们的ip是动态的,同域名解析一样,cdn的回源配置也不可能要我们手动去改回源ip,既然我们有DDNS,那么cdn有没有这样的功能呢?监测ip变动,自动修改回源ip?大厂有没有我不知道,小厂绝对没有。那么这就麻烦了?NONONO,别忘了有些CDN也支持域名回源的!在源服务器和 a.com 之间,我们给他加多一个 b.com ,这个 b.com 的作用就是配合DDNS,如同上面所讲,b.com 只需加一个端口号也能正常访问到网站,不过我们现在的任务是需要去掉域名端口也能正常访问,那么 b.com 承担的就是<工具人>的角色。假设 b.com:1234 能够正常返回原站,那么我们给 a.com 套上cdn,回源目标为 b.com:1234 ,那么只要我们访问a.com,不就能直接访问源服务器嘛?再也不用加端口了!!!
举例来了:我想通过 123.com 访问源站,我们加一个中转域名,假设为 redirect.123.com ,配置好DDNS后, redirect.123.com 加上一个服务端口就能访问源站,然后 123.com 套上cdn,回源为 redirect.123.com:服务端口,这样通过 123.com 就能访问源站了~~~
所以呢,不要用正式域名来配置DDNS,如果你这样做了,换一个域名~~~
只要原理理解了,配置并不难
腾讯云配置实例
阿里云配置实例
另外说一句,我们可以DDNS和第三方内网穿透共用,使用腾讯云的热备原站回源方法,当一个源站回源失败,就可以通过另外一个源站回源,有备无患。假设DDNS废了,还有第三方的内网穿透撑腰,就没事了
找到合适你CDN,按图配置就行了,然后去云解析DNS解析CDN提供的cname,完美访问!去掉端口这个小尾巴了,看起来真舒服!要是已备案的域名,还可以使用大陆CDN,速度一点也不会差
第二个,就是不推荐使用的隐性url解析方法了:
正如前文所讲:
隐性url的缺点(流量站大忌!)
隐性url有一个很大很大,甚至是致命的问题,首先,隐性url解析是基于iframe实现的,这对搜索引擎的蜘蛛非常不友好,注重seo的兄弟千万不能使用,第二,在浏览器中显示的域名永远都是隐性url记录的解析值,无论你怎么点内部链接,浏览器永远就显示那个域名,用户看了会摸不着头脑。可以这样理解:我建个博客,域名为123.com,使用了隐性url解析,我打开一篇文章,发现url还是原来的123.com,大受震撼。我登陆wordpress后台,url输入123.com/wp-admin,(刻进DNA的链接),发现页面正常跳转,但是浏览器显示的url还是原来的123.com???有用户看到的话,绝对以为闹鬼了。那么蜘蛛要来爬你的站,发现一个域名指向了一堆不同的页面,你让他怎么想?它还会来爬吗?
但是,如果网站是自己用,或者是静态网页,没有那么多子链接,隐性url是非常可取的。我们也不要忘记他的优点:可以直接回源!无需经过第三方CDN分发
我没钱,所以就用阿里云作例子吧:
也是非常简单的,只是域名一定要备案!不然就会这样:
当然你也可以用显性url,你可以理解为301重定向,只不过重定向是在DNS服务器完成的~当然域名会变化~
访问一下我们的网站,完美回源,没有端口!哦耶!家建服务器正式运行!
还是要提醒一下,因为公网ip会变动,例如ssh或者宝塔面板登录需要用到ip,所以就可能要依赖内网穿透实现这些服务了!当然,宝塔面板也可以绑定域名访问的~自己琢磨吧!内网穿透教程拖到下面看~
教程到此结束!感谢你能看到这里,希望本文能够对您有所启发!本来我也想过何必费那么大周折就搞这,还不如买台云服务器省心,应该就是纯粹享受折腾的过程罢了!ヾ(≧▽≦*)o
更多文章查看:
https://rosmontis.com/archives/1798 作者:Rosmontis—– https://www.bilibili.com/read/cv15787877 出处:bilibili
Good day! I just would like to offer you a huge thumbs up for the great info you’ve got right here on this post. I’ll be returning to your website for more soon.
I’m amazed, I must say. Rarely do I come across a blog that’s equally educative and interesting, and without a doubt, you’ve hit the nail on the head. The issue is something which too few people are speaking intelligently about. Now i’m very happy I stumbled across this in my search for something relating to this.
You have made some good points there. I looked on the internet to find out more about the issue and found most people will go along with your views on this web site.
Aw, this was an exceptionally good post. Finding the time and actual effort to generate a top notch article… but what can I say… I hesitate a whole lot and don’t seem to get anything done.
I needed to thank you for this fantastic read!! I definitely loved every bit of it. I have you book marked to check out new stuff you post…
The next time I read a blog, Hopefully it does not disappoint me just as much as this one. After all, Yes, it was my choice to read through, but I actually thought you’d have something helpful to talk about. All I hear is a bunch of crying about something you can fix if you were not too busy seeking attention.
Very good write-up. I certainly love this website. Keep it up!
This site was… how do you say it? Relevant!! Finally I’ve found something that helped me. Thanks a lot.
Having read this I believed it was really enlightening. I appreciate you spending some time and energy to put this content together. I once again find myself spending a significant amount of time both reading and posting comments. But so what, it was still worth it.
Bethlehem, which means “home of bread,” was additionally the house of David, one of God’s favorite kings.
Howdy! I simply would like to give you a big thumbs up for your excellent information you’ve got right here on this post. I am returning to your site for more soon.
This theme often consists of components inspired by basic films and stars.
Later that day, Gates’ division arrived in camp, which by then included solely 600 Continental Army forces following the end of many enlistments, to secure the northern frontier.
For instance, Boutique inns just like the Blue Moon Resort in New York have seen elevated efficiency and visitor booking charges by using Cloudbeds.
This is a very good tip especially to those new to the blogosphere. Brief but very accurate information… Appreciate your sharing this one. A must read article!
Good day! I just wish to give you a big thumbs up for the great information you have here on this post. I will be returning to your web site for more soon.
Survivors are two daughters, Mrs.
Hi! I simply want to give you a huge thumbs up for the great information you have right here on this post. I’ll be returning to your website for more soon.
Burial shall be in the Bailey Cemetery with Callaway-Smith-Cobb Funeral House accountable for arrangements.
After exploring a few of the blog articles on your web page, I seriously like your technique of writing a blog. I bookmarked it to my bookmark website list and will be checking back soon. Take a look at my web site too and let me know what you think.
The next day, around 100,000 houses and businesses in New Jersey remained without power.
After I initially commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve four emails with the same comment. There has to be a means you can remove me from that service? Thanks.
Good information. Lucky me I discovered your blog by chance (stumbleupon). I have bookmarked it for later!
Suger described the finished work at Saint-Denis as “a circular string of chapels, by advantage of which the entire church would shine with the wonderful and uninterrupted mild of most luminous windows, pervading the interior magnificence”.
St. Mary’s Church, which is the most important brick church on this planet.
Sure, it’s not tremendous authentic and still has a great deal of tropes.
Nice post. I learn something new and challenging on blogs I stumbleupon on a daily basis. It will always be helpful to read content from other writers and practice a little something from their websites.
Elizabeth died in 1777 whereas he was imprisoned as a Loyalist in the course of the American Revolutionary Battle.
Your style is unique in comparison to other folks I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just book mark this blog.
Massive pool gear storage covers are extra like sheds.
You ought to be a part of a contest for one of the highest quality sites on the web. I am going to recommend this site!
The murals were additionally featured in a scene in the film Rain Man starring Dustin Hoffman and Tom Cruise.
I love it when people get together and share thoughts. Great blog, keep it up!
Everyone loves it when individuals get together and share ideas. Great site, keep it up.
You should be a part of a contest for one of the finest sites on the net. I will recommend this website!
Right here is the perfect webpage for everyone who would like to find out about this topic. You realize a whole lot its almost hard to argue with you (not that I actually would want to…HaHa). You certainly put a fresh spin on a topic which has been discussed for ages. Great stuff, just excellent.
Hi there! This article could not be written any better! Looking through this article reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will forward this article to him. Pretty sure he’s going to have a great read. Many thanks for sharing!
You should take part in a contest for one of the highest quality blogs on the internet. I most certainly will highly recommend this site!
This site really has all the information and facts I wanted about this subject and didn’t know who to ask.
An intriguing discussion is definitely worth comment. I do think that you should publish more about this subject, it may not be a taboo matter but generally people do not discuss these topics. To the next! All the best.
I would like to thank you for the efforts you’ve put in penning this website. I really hope to see the same high-grade blog posts from you later on as well. In fact, your creative writing abilities has inspired me to get my very own website now 😉
French bulldogs develop and develop (hips, joints, immune programs, and so forth.) up until 18-24 months of age so these are essential levels and the care you are taking of your Frenchie now may also help him grow to be the healthiest grownup canine doable!
Most pedals we promote together with our ARDX20 delay, AMAZE1 controller, Prince of Tone, and so on are in inventory and able to ship!
Little India, Chinatown and the Kampung Glam are the city’s ethnic corners.
Very good post. I am experiencing many of these issues as well..
I’m amazed, I must say. Rarely do I come across a blog that’s both educative and amusing, and without a doubt, you’ve hit the nail on the head. The problem is an issue that too few folks are speaking intelligently about. Now i’m very happy that I came across this in my hunt for something concerning this.
After going over a number of the blog posts on your web site, I really like your way of blogging. I book-marked it to my bookmark website list and will be checking back soon. Please check out my website too and let me know your opinion.
A lot of our system stuff had to be rethought relatively late within the mission.
After looking over a handful of the blog articles on your blog, I seriously appreciate your technique of blogging. I saved as a favorite it to my bookmark website list and will be checking back soon. Please visit my website as well and let me know what you think.
Would you wish to adorn your self with a Aliff Laila made Inexperienced Hoop Earrings or go for a fashionable Multicoloured Bracelet?
Funeral providers were held Friday, February 21 at 10:00 AM in the Wilkerson Chapel with The Rev.
Saved as a favorite, I really like your blog.
bookmarked!!, I love your web site.
Everything is very open with a very clear description of the issues. It was definitely informative. Your site is useful. Thank you for sharing!
Having read this I believed it was rather enlightening. I appreciate you finding the time and effort to put this informative article together. I once again find myself personally spending a significant amount of time both reading and commenting. But so what, it was still worth it.
Having read this I believed it was extremely informative. I appreciate you finding the time and energy to put this information together. I once again find myself personally spending a lot of time both reading and leaving comments. But so what, it was still worthwhile!
I would like to thank you for the efforts you’ve put in penning this website. I’m hoping to view the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has motivated me to get my own, personal site now 😉
I could not resist commenting. Well written.
The quickest approach to connect with somebody is through tales!
I blog often and I really thank you for your content. The article has truly peaked my interest. I will book mark your website and keep checking for new information about once a week. I opted in for your RSS feed as well.
Or You possibly can put on Firoza stone on Fridays, and it’s also suitable on Saturdays.
I’d like to thank you for the efforts you have put in writing this blog. I really hope to view the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has encouraged me to get my own website now 😉
Services for Rubie Mendel, 90, of Palestine have been held Wednesday.
Hi there! I could have sworn I’ve visited your blog before but after looking at a few of the articles I realized it’s new to me. Anyhow, I’m definitely pleased I stumbled upon it and I’ll be book-marking it and checking back often.
It’s nearly impossible to find well-informed people in this particular subject, however, you seem like you know what you’re talking about! Thanks
Spot on with this write-up, I absolutely believe this web site needs much more attention. I’ll probably be returning to read through more, thanks for the advice.
It is a pooch that is likely to be better suited to suburban or nation dwelling.
Every commissioner is assigned a specific division to oversee during their time period in office.
Great information. Lucky me I discovered your website by chance (stumbleupon). I have saved it for later.
This slim wallet card fits perfectly in his pocket, conserving your love close wherever he goes.
Way cool! Some extremely valid points! I appreciate you penning this post plus the rest of the site is really good.
We additionally launched genetically manipulated animals and even some alien-wanting creatures, all of which grew naturally out of our recreation fiction.
The secret to a sparkling brilliant swimming pool is regular maintenance.
Hi, I do think this is an excellent blog. I stumbledupon it 😉 I may revisit yet again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to help others.
I blog frequently and I truly appreciate your content. This great article has truly peaked my interest. I’m going to book mark your website and keep checking for new details about once per week. I opted in for your Feed too.
After exploring a handful of the blog posts on your website, I truly appreciate your way of blogging. I added it to my bookmark website list and will be checking back in the near future. Please visit my website as well and tell me how you feel.
Way cool! Some extremely valid points! I appreciate you penning this post plus the rest of the website is also really good.
Way cool! Some very valid points! I appreciate you writing this write-up and also the rest of the site is also very good.
Next time I read a blog, Hopefully it won’t disappoint me just as much as this particular one. I mean, I know it was my choice to read through, nonetheless I actually believed you would probably have something interesting to talk about. All I hear is a bunch of whining about something you can fix if you were not too busy seeking attention.
May I simply say what a comfort to uncover an individual who truly knows what they are talking about on the net. You actually know how to bring a problem to light and make it important. More and more people need to check this out and understand this side of the story. It’s surprising you aren’t more popular since you most certainly possess the gift.
Howdy! I just want to offer you a big thumbs up for your excellent information you have got here on this post. I will be returning to your website for more soon.
Right here is the right website for anyone who would like to understand this topic. You understand so much its almost hard to argue with you (not that I actually would want to…HaHa). You certainly put a fresh spin on a topic that’s been discussed for ages. Great stuff, just wonderful.
Good blog post. I definitely love this website. Continue the good work!
That is a good tip particularly to those fresh to the blogosphere. Brief but very precise information… Many thanks for sharing this one. A must read article.
Good article. I certainly love this site. Thanks!
I could not refrain from commenting. Well written!
This blog was… how do you say it? Relevant!! Finally I have found something which helped me. Appreciate it.
Watch our exclusive Neerfit sexy bf video on neerfit.co.in.
Hello! I could have sworn I’ve visited this website before but after going through a few of the posts I realized it’s new to me. Anyhow, I’m definitely happy I found it and I’ll be bookmarking it and checking back regularly!
Saved as a favorite, I love your web site.
But there is a cut-off date on when the stock must be purchased by, so it is important to research earlier than shopping for in.
Apart from the usual technical evaluation, there can also be elementary evaluation.
super content. thanks for your effort
Everything is very open with a really clear explanation of the issues. It was definitely informative. Your site is useful. Thanks for sharing.
It’s hard to come by experienced people about this subject, however, you sound like you know what you’re talking about! Thanks
This excellent website certainly has all the info I needed concerning this subject and didn’t know who to ask.
May I simply say what a relief to discover somebody who truly knows what they are discussing online. You certainly know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. It’s surprising you aren’t more popular given that you certainly possess the gift.
I was able to find good information from your content.
Operating water and brown rice are beneficial strategies for cleansing this grounding stone.
I need to to thank you for this good read!! I absolutely enjoyed every bit of it. I’ve got you book-marked to check out new things you post…
Hello! I could have sworn I’ve been to this website before but after going through a few of the articles I realized it’s new to me. Anyways, I’m definitely delighted I discovered it and I’ll be bookmarking it and checking back frequently!
I’m impressed, I must say. Rarely do I come across a blog that’s both equally educative and interesting, and let me tell you, you’ve hit the nail on the head. The issue is something that too few men and women are speaking intelligently about. I am very happy I found this during my search for something regarding this.