网站添加ipv6访问

今天折腾境外vps的时候忽然想到5刀每个月的服务器都有ipv6,为何国内服务器默认就不给ipv6呢?现在都2020年了,网站该支持ipv6访问了吧?!!于是查阅各方文档,终于给网站添加了ipv6,目前本站已支持ipv6访问。

本文简要介绍给网站添加ipv6的配置过程。

配置流程

1. 首先服务器要有ipv6地址。如果是海外vps,大部分情况下都有(或者可在网页控制台直接添加)。国内的情形比较特殊,例如本人用的阿里云就需要申请ipv6内测资格等一系列复杂操作才能用上ipv6。阿里云服务器添加ipv6的教程请参考:https://help.aliyun.com/document_detail/100901.html?spm=a2c4g.11186623.6.907.207779323rt1Ly

有ipv6公网地址后,Linux系统在终端输入 ip addr, 会有类似输出:

inet6 240b:4001:1:400:e72d:dab:c902:b662/64 scope global
   valid_lft forever preferred_lft forever
inet6 fe80::216:3eff:fe01:c27b/64 scope link
   valid_lft forever preferred_lft forever

注意:

  1. 根据ipv6规范,必须要有两个ipv6地址,其中一个是本地的link,以及外界能访问的global。如果你的系统输出没有global,说明没有公网ipv6地址,请咨询vps运营商帮忙处理;
  2. 在阿里云申请ipv6地址后,请记得到安全组放行ipv6的相应端口。

2. 配置web服务器软件/中间件监听ipv6流量。本人用的Nginx,配置上就很简单了,添加一行listen即可:

server {
    listen 80;
    listen [::]:80;
    server_name www.tlanyan.me tlanyan.me;
    rewrite ^(.*) https://$server_name$1 permanent;
}

server {
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;
    server_name www.tlanyan.me tlanyan.me;
    # 一些其他配置
}

配置好后用 nginx -t 测试有无配置错误,没有的话用 systemctl restart nginx 重启。

注意:

  1. 从Nginx 1.3开始,ipv6only默认是on,请勿在监听ipv6的行添加ipv6only=on,否则会出现“nginx: [emerg] duplicate listen options for [::]:80”的错误!
  2. 如果你启用了ip6tables,请记得放行相应端口。

3. 登录dns解析后台,添加AAAA记录,指向ipv6地址。添加成功后,可通过 nslookup 等工具查看解析到的ipv6地址:

[tlanyan@node13 ~]$ nslookup tlanyan.me
Server:		100.100.2.136
Address:	100.100.2.136#53

Non-authoritative answer:
Name:	tlanyan.me
Address: 47.75.187.245
Name:	tlanyan.me
Address: 240b:4001:1:400:e72d:dab:c902:b662

如果你的客户端有ipv6地址,可以通过 ping -6 tlanyan.me 类似的方式查看域名的ipv6地址。

4. 测试网站是否已经成功配置ipv6。本人推荐使用 https://ipv6-test.com/validate.php 提供的服务。例如测试本站:

ipv6测试结果ipv6测试结果

如果你熟悉命令行,也可以使用 curl -6 https://tlanyan.me 等工具测试。

如果测试通过,恭喜你,你的网站已经正式支持ipv6了!

其它

1. 目前国内校园网基本都已覆盖了ipv6,如果你自己加过路由器,要买支持ipv6的路由器,以及正确配置ipv6相关设置才能在手机、笔记本上获得ipv6地址;

2. 中国移动、电信等宽带默认也给ipv6地址,请记得用支持ipv6的路由器。

参考

  1. Difference between link-local and global link addresses in ISATAP
  2. Nginx监听IPv6地址端口的正确操作方法
  3. Nginx duplicate listen options for [::]:80 error

 

留言评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select * from vps_autoblog_queue where is_running >0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=6 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=6 and source_url_key='85f8e27ce55bd78fd33f47d2b1409198'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(6,'https://www.hijk.pw/post-sitemap.xml','85f8e27ce55bd78fd33f47d2b1409198',1750370287,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=4 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=4 and source_url_key='54b1dccf98c13c81f546faf82132bc77'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(4,'https://ssr.tools/sitemap-posttype-post.2020.xml','54b1dccf98c13c81f546faf82132bc77',1750370287,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=2 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=2 and source_url_key='91372ddcd9e4809b115feaa5b6f00815'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(2,'https://tlanyan.me/post-sitemap.xml','91372ddcd9e4809b115feaa5b6f00815',1750370287,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=7 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=7 and source_url_key='569e17863f7693f1afa9e9256af9dcff'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(7,'https://aisoa.cn/sitemap.xml','569e17863f7693f1afa9e9256af9dcff',1750370287,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=9 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=9 and source_url_key='cc9416f8df40d8c3a48e66856b1cd6fd'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(9,'https://www.v2rayssr.com/sitemap.xml','cc9416f8df40d8c3a48e66856b1cd6fd',1750370287,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=10 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=10 and source_url_key='74714f67855820f0c701ce905b231f27'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(10,'https://doubibackup.com/sitemap.xml','74714f67855820f0c701ce905b231f27',1750370287,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,is_running,last_post_time,post_interval,not_check_stoped from vps_autoblog_queue WHERE is_running>0 and fetched=0 order BY id ASC

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,sn_id from vps_autoblog_queue WHERE is_running=0 and fetched=0 order BY id ASC LIMIT 1