moneyslow.com

Nginx:如何安装配置Ipv6网络

Nginx:如何安装配置Ipv6网络

Nginx:如何安装配置Ipv6网络

本文讨论Nginx支持HTTP/2, SSL (IPv6+IPv4)

如果是源码编译安装nginx的,就是这样的:

# cd /path/to/nginx-src-code/
# ./configure --without-http_autoindex_module --without-http_userid_module \
--without-http_auth_basic_module --without-http_geo_module \
--without-http_fastcgi_module --without-http_empty_gif_module \
--with-poll_module --with-http_stub_status_module \
--with-http_ssl_module --with-ipv6
# make install

编译完成后,通过如下命令进行检验:
nginx -V 2>&1 >/dev/null | grep --color -o with-ipv6
如果有显示ipv6,就代表你的nginx可以进行ipv6配置了:
vi /usr/local/nginx/conf/nginx.conf
有几种情况:

ipv4和ipv6都绑定80端口:

# IPv4
listen :80;
# IPv6
listen [::]:80;
其实也可以合并成一行:
listen [::]:80;

ipv4不绑定,ipv6绑定80和443:

listen [::]:443 default ipv6only=on;
listen [::]:80 default ipv6only=on;

如果需要HTTP/2+SSL:

# port 443 IPv4 with http2 and ssl
listen 443 ssl http2;
# port 443 IPv6 with http2 and ssl
listen [::]:443 ssl http2;
# port 80 IPv4
listen *:80;
listen [::]:80;
# my server name 🙂
server_name ipv6.moneyslow.com;

如果想只监听在ipv6地址上,就可以这样:

listen [2001:19f0:6001:2d26:5400:2ff:fea3:86d]:80;

如果想测试ipv6地址的速度,可以看这篇文章:

Exit mobile version