Nginx配置支持IPV6地址的方法示例

 更新时间:2024年11月11日 09:10:35   作者:zxguan  
本文主要介绍了如何搭建并测试Nginx以支持IPV6地址的过程,包括下载安装包、编译安装、配置和启动Nginx等步骤,同时,文章还解决了在测试IPV6地址时遇到的两个问题:curl解析错误和阿里云、腾讯云IPV6地址配置问题

搭建并测试

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地址内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 详解php+nginx 服务发生500 502错误排查思路

    详解php+nginx 服务发生500 502错误排查思路

    这篇文章主要介绍了详解php+nginx 服务发生500 502错误排查思路,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-07-07
  • Nginx Rewrit实现网页跳转功能详细步骤

    Nginx Rewrit实现网页跳转功能详细步骤

    Rewrite主要实现url地址重写,以及重定向,就是把传入web的请求重定向到其他url的过程,这篇文章主要介绍了Nginx Rewrit实现网页跳转功能详细步骤,需要的朋友可以参考下
    2024-02-02
  • 浅谈nginx基于请求头或请求内容的防护

    浅谈nginx基于请求头或请求内容的防护

    本文主要介绍了浅谈nginx基于请求头或请求内容的防护,通常涉及到对请求进行过滤,检查其是否包含某些特定的值或模式,感兴趣的可以了解一下
    2023-10-10
  • Nginx可视化管理软件NginxProxyManager的使用

    Nginx可视化管理软件NginxProxyManager的使用

    NginxProxyManager是一款基于Nginx的开源可视化管理工具,支持通过WebUI简易管理Nginx服务器,支持DockerCompose快速部署在Linux、Windows、macOS上,提供SSL证书获取、多代理管理等功能,感兴趣的可以了解一下
    2024-11-11
  • Nginx的location的常见规则优先级问题

    Nginx的location的常见规则优先级问题

    Nginx是反向代理和负载均衡的首选工具,nginx的location配置有许多细节内容在网上不容易找到资料,或者解释不清。本文对Nginx location规则优先级介绍,需要的朋友参考下吧
    2021-08-08
  • 使用google-perftools优化nginx在高并发时的性能的教程(完整版)

    使用google-perftools优化nginx在高并发时的性能的教程(完整版)

    如果使用googler开发的google-perftools优化Nginx和MySQL的内存管理,性能将会有一定程度的提升。特别是对高并发下的服务器,效果更明显
    2013-02-02
  • Nginx 安装详细教程

    Nginx 安装详细教程

    Nginx是一款自由的、开源的、高性能的HTTP服务器和反向代理服务器,这篇文章主要介绍了Nginx 安装详细教程,需要的朋友可以参考下
    2020-02-02
  • nginx host绕过的三种方式

    nginx host绕过的三种方式

    本文主要介绍了nginx host绕过的三种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-03-03
  • nginx虚拟主机配置实例详解

    nginx虚拟主机配置实例详解

    这篇文章主要介绍了nginx虚拟主机配置实例详解的相关资料,需要的朋友可以参考下
    2017-06-06
  • Nginx 如何限制访问频率,下载速率和并发连接数的方法

    Nginx 如何限制访问频率,下载速率和并发连接数的方法

    这篇文章主要介绍了Nginx 如何限制访问频率,下载速率和并发连接数的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-08-08

最新评论