搭建并测试
1. 下载 ng 安装包
点击进入 nginx 网址,下载安装包
2. 安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel
3. 上传并解压安装包
// 进入指定目录,ftp 上传压缩包 tar -zxvf nginx-1.26.2.tar.gz
4. 编译
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-ipv6
5. 安装
make && make install
6. 修改配置
# 进入 ng 配置文件夹 cd /usr/local/nginx/conf # 修改 ng 配置文件 vim nginx.conf
http { ...... server { ...... listen 80; # ipv4 listen [::]:80; # ipv6 ...... } ...... }
7. 启动 ng
# 启动 ng ./nginx # 停止 ng ./nginx -s stop # 重启 ng ./nginx -s reload
8. 查看 ip 地址
[root@izf8z6w83m8z8cj3m3lmubz conf]# ip a 1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state unknown group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state up group default qlen 1000 link/ether 00:16:3e:0a:74:78 brd ff:ff:ff:ff:ff:ff inet 172.18.133.39/20 brd 172.18.143.255 scope global dynamic eth0 valid_lft 315340442sec preferred_lft 315340442sec inet6 2408:4008:1105:4901:b3f7:6c00:f1d7:e412/64 scope global valid_lft forever preferred_lft forever
9. 测试 ip 地址
9.1. 测试 ipv4 地址
[root@izf8z6w83m8z8cj3m3lmubz conf]# curl 172.18.133.39:80 <!doctype html> <html> <head> <title>welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: tahoma, verdana, arial, sans-serif; } </style> </head> <body> <h1>welcome to nginx!</h1> <p>if you see this page, the nginx web server is successfully installed and working. further configuration is required.</p> <p>for online documentation and support please refer to <a href="http://nginx.org/" rel="external nofollow" rel="external nofollow" >nginx.org</a>.<br/> commercial support is available at <a href="http://nginx.com/" rel="external nofollow" rel="external nofollow" >nginx.com</a>.</p> <p><em>thank you for using nginx.</em></p> </body> </html>
9.2. 测试 ipv6 地址
[root@izf8z6w83m8z8cj3m3lmubz conf]# curl -6 -g http://[2408:4008:1105:4901:b3f7:6c00:f1d7:e412]:80 [root@izf8z6w83m8z8cj3m3lmubz conf]# curl http://2408:4008:1105:4901:b3f7:6c00:f1d7:e412:80 <!doctype html> <html> <head> <title>welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: tahoma, verdana, arial, sans-serif; } </style> </head> <body> <h1>welcome to nginx!</h1> <p>if you see this page, the nginx web server is successfully installed and working. further configuration is required.</p> <p>for online documentation and support please refer to <a href="http://nginx.org/" rel="external nofollow" rel="external nofollow" >nginx.org</a>.<br/> commercial support is available at <a href="http://nginx.com/" rel="external nofollow" rel="external nofollow" >nginx.com</a>.</p> <p><em>thank you for using nginx.</em></p> </body> </html>
ipv6 测试失败原因
1. curl: [globbing] error: bad range specification after pos 9
ipv6
地址中含有 :
等符号,可能在解析时报错,需要使用 []
将 ipv6
地址包起来,避免解析报错。
# 错误写法 curl http://[2408:4008:1105:4901:b3f7:6c00:f1d7:e412] 或 curl http://[2408:4008:1105:4901:b3f7:6c00:f1d7:e412:80]
2. curl: failed to connect to 0.0.0.10: invalid argument
原因存在多种,我遇到是一个比较奇葩的原因。在阿里云和腾讯云中,curl 指定的 ipv6 地址必须与控制台分配的 ipv6 地址一致,自己手动配置的不行。
到此这篇关于nginx配置支持ipv6地址的方法示例的文章就介绍到这了,更多相关nginx配置支持ipv6地址内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论