Both centos nginx configuration ipv4 and ipv6 addresses can access the same website

The title centos nginx configures both ipv4 and ipv6 addresses to access the same website

It is relatively simple to configure in Nginx that both IPv4 and IPv6 addresses can access the same website. Just make sure that the Nginx configuration file is properly configured with listeners for both IPv4 and IPv6 addresses.

  1. Open your Nginx configuration file, usually located in the /etc/nginx/nginx.confor /etc/nginx/conf.d/directory.
  2. Edit the configuration file and add the following to configure listeners IPv4and IPv6addresses:
server {
    
    
    listen 80;                    # 监听IPv4地址的80端口
    listen [::]:80 ipv6only=on;   # 监听IPv6地址的80端口
    server_name example.com;      # 设置你的域名

    location / {
    
    
        # 配置其他的网站设置,比如代理、反向代理等
    }
}

In the example above, listen 80the ; part means listen IPv4 地址的 80 端口while the listen [::]:80 ipv6only=on; part means listen IPv6 地址的 80 端口and enable the ipv6only option.

Guess you like

Origin blog.csdn.net/weixin_44021888/article/details/132316558