0


Nginx 学习之 配置支持 IPV6 地址

目录

搭建并测试

1. 下载 NG 安装包

点击进入 Nginx 网址,下载安装包
在这里插入图片描述

2. 安装编译工具及库文件

  1. yum -yinstallmake zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel

3. 上传并解压安装包

  1. // 进入指定目录,ftp 上传压缩包
  2. tar-zxvf nginx-1.26.2.tar.gz

4. 编译

  1. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-ipv6

5. 安装

  1. make&&makeinstall

6. 修改配置

  1. # 进入 NG 配置文件夹cd /usr/local/nginx/conf
  2. # 修改 NG 配置文件vim nginx.conf
  1. http {......
  2. server {......
  3. listen 80;# IPV4
  4. listen [::]:80;# IPV6......}......}

7. 启动 NG

  1. # 启动 NG
  2. ./nginx
  3. # 停止 NG
  4. ./nginx -s stop
  5. # 重启 NG
  6. ./nginx -s reload

8. 查看 IP 地址

  1. [root@iZf8z6w83m8z8cj3m3lmubZ conf]# ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  2. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  3. inet 127.0.0.1/8 scope host lo
  4. valid_lft forever preferred_lft forever
  5. inet6 ::1/128 scope host
  6. valid_lft forever preferred_lft forever
  7. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
  8. link/ether 00:16:3e:0a:74:78 brd ff:ff:ff:ff:ff:ff
  9. inet 172.18.133.39/20 brd 172.18.143.255 scope global dynamic eth0
  10. valid_lft 315340442sec preferred_lft 315340442sec
  11. inet6 2408:4008:1105:4901:b3f7:6c00:f1d7:e412/64 scope global
  12. valid_lft forever preferred_lft forever

9. 测试 IP 地址

9.1. 测试 IPV4 地址

  1. [root@iZf8z6w83m8z8cj3m3lmubZ conf]# curl 172.18.133.39:80<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>
  2. html { color-scheme: light dark;}
  3. body { width: 35em; margin: 0 auto;
  4. 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
  5. working. Further configuration is required.</p><p>For online documentation and support please refer to
  6. <a href="http://nginx.org/">nginx.org</a>.<br/>
  7. Commercial support is available at
  8. <a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>

9.2. 测试 IPV6 地址

  1. [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>
  2. html { color-scheme: light dark;}
  3. body { width: 35em; margin: 0 auto;
  4. 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
  5. working. Further configuration is required.</p><p>For online documentation and support please refer to
  6. <a href="http://nginx.org/">nginx.org</a>.<br/>
  7. Commercial support is available at
  8. <a href="http://nginx.com/">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

  1. IPV6

地址中含有

  1. :

等符号,可能在解析时报错,需要使用

  1. []

  1. IPV6

地址包起来,避免解析报错。

  1. # 错误写法curl http://[2408:4008:1105:4901:b3f7:6c00:f1d7:e412]
  2. curl http://[2408:4008:1105:4901:b3f7:6c00:f1d7:e412:80]

2. curl: Failed to connect to 0.0.0.10: Invalid argument

原因存在多种,我遇到是一个比较奇葩的原因。

  1. 在阿里云和腾讯云中,curl 指定的 IPV6 地址必须与控制台分配的 IPV6 地址一致,自己手动配置的不行。
标签: nginx 学习 服务器

本文转载自: https://blog.csdn.net/DreamStar2560/article/details/141334762
版权归原作者 zxguan 所有, 如有侵权,请联系我们删除。

“Nginx 学习之 配置支持 IPV6 地址”的评论:

还没有评论