Nginx配置支持IPV6地址的方法示例
搭建并測(cè)試
1. 下載 NG 安裝包
點(diǎn)擊進(jìn)入 Nginx 網(wǎng)址,下載安裝包

2. 安裝編譯工具及庫(kù)文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel
3. 上傳并解壓安裝包
// 進(jìn)入指定目錄,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. 修改配置
# 進(jìn)入 NG 配置文件夾 cd /usr/local/nginx/conf # 修改 NG 配置文件 vim nginx.conf
http {
......
server {
......
listen 80; # IPV4
listen [::]:80; # IPV6
......
}
......
}
7. 啟動(dòng) NG
# 啟動(dò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. 測(cè)試 IP 地址
9.1. 測(cè)試 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 rel="external nofollow" rel="external nofollow" >nginx.org</a>.<br/>
Commercial support is available at
<a rel="external nofollow" rel="external nofollow" >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
9.2. 測(cè)試 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 rel="external nofollow" rel="external nofollow" >nginx.org</a>.<br/>
Commercial support is available at
<a rel="external nofollow" rel="external nofollow" >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
IPV6 測(cè)試失敗原因
1. curl: [globbing] error: bad range specification after pos 9
IPV6 地址中含有 : 等符號(hào),可能在解析時(shí)報(bào)錯(cuò),需要使用 [] 將 IPV6 地址包起來(lái),避免解析報(bào)錯(cuò)。
# 錯(cuò)誤寫(xiě)法 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
原因存在多種,我遇到是一個(gè)比較奇葩的原因。在阿里云和騰訊云中,curl 指定的 IPV6 地址必須與控制臺(tái)分配的 IPV6 地址一致,自己手動(dòng)配置的不行。
到此這篇關(guān)于Nginx配置支持IPV6地址的方法示例的文章就介紹到這了,更多相關(guān)Nginx配置支持IPV6地址內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx?location和proxy_pass配置示例詳解
這篇文章主要介紹了Nginx?location和proxy_pass配置的相關(guān)資料,本文詳細(xì)探討了Nginx配置中`location`和`proxy_pass`指令的不同組合方式及其對(duì)請(qǐng)求轉(zhuǎn)發(fā)路徑的影響,通過(guò)列舉多種組合,展示了`location`匹配目錄與`proxy_pass`地址路徑如何相互作用,需要的朋友可以參考下2024-11-11
nginx從安裝到配置詳細(xì)說(shuō)明(安裝,安全配置,防盜鏈,動(dòng)靜分離,配置 HTTPS,性能優(yōu)化)
這篇文章主要介紹了nginx從安裝到配置詳細(xì)說(shuō)明(安裝,安全配置,防盜鏈,動(dòng)靜分離,配置 HTTPS,性能優(yōu)化,緩存,url重寫(xiě)),需要的朋友可以參考下2022-01-01
在nginx中實(shí)現(xiàn)單位時(shí)間內(nèi)限制訪問(wèn)頻率的教程
這篇文章主要介紹了在nginx中實(shí)現(xiàn)單位時(shí)間內(nèi)限制訪問(wèn)頻率的教程,并非針對(duì)IP而是全局的訪問(wèn)量限制,需要的朋友可以參考下2015-04-04
Apache和Nginx實(shí)現(xiàn)虛擬主機(jī)的3種方式小結(jié)
Apache是一個(gè)模型化的服務(wù)器,可以運(yùn)行在幾乎所有的服務(wù)器上。其屬于應(yīng)用服務(wù)器,這篇文章主要介紹了Apache和Nginx實(shí)現(xiàn)虛擬主機(jī)的3種方式,需要的朋友可以參考下2023-11-11
Nginx配置PATHINFO隱藏thinkphp index.php
這篇文章主要介紹了Nginx配置PATHINFO隱藏thinkphp index.php,本文直接給出配置示例,需要的朋友可以參考下2015-07-07

