others-How to enable ipv6 in nginx/openresty/kong?

1. Purpose

In this post I would demonstrate how to support ipv6 in nginx/openresty or kong.


2. The solution

2.1 What is nginx, openresty or kong?

NGINX

Nginx is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more.

And NGINX is a software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. It is a web server that also acts as an email proxy, reverse proxy, and load balancer. The software’s structure is asynchronous and event-driven; which enables the processing of many requests at the same time. NGINX is highly scalable as well, meaning that its service grows along with its clients’ traffic.

OpenResty

OpenResty is a dynamic web server that is based on Nginx and LuaJIT built by the Chinese Zhang Yichun. LuaJIT is a just-in-time compiler of the Lua programming language. Lua is a powerful, dynamic, and lightweight programming language. The design purpose of the language is to be embedded in the application, so as to provide flexible extension and customization functions for the application. OpenResty is an extensible web platform realized by using Lua to extend Nginx. At present, OpenResty is mostly used in the development of API gateways. Of course, it can also be used to replace Nginx for reverse proxy and load balancing scenarios.

OpenResty is based on Nginx and LuaJIT, so OpenResty inherits the multi-process architecture of Nginx. Each worker process is obtained by fork of the Master process. In fact, the LuaJIT virtual machine in the Master process will also fork together. come over. All coroutines in the same Worker will share this LuaJIT virtual machine, and the execution of Lua code is also done in this virtual machine. At the same point in time, each Worker process can only process one user’s request, that is, only one coroutine is running.

kong

Kong is a cloud-native, efficient, scalable, and distributed microservice abstraction layer, known as an API gateway, or API middleware. Kong was open sourced by Mashape in April 2015, built on OpenResty and Apache Cassandra/PostgreSQL, providing an easy-to-use RESTful API to operate and configure the API system.

kong is based on nginx and openresty:


2.2 What is ipv6

IPv6 is the abbreviation of “Internet Protocol Version 6” (Internet Protocol Version 6) in English. It is the next-generation IP protocol designed by the Internet Engineering Task Force (IETF) to replace IPv4. Grains of sand make up an address.

IPv6 offers the following improvements over IPv4:

  • More efficient routing without fragmenting packets
  • Built-in Quality of Service (QoS) that differentiates latency-sensitive packets
  • Eliminate NAT to expand address space from 32 bits to 128 bits
  • Built-in network layer security (IPsec)
  • Stateless address autoconfiguration makes network management easier
  • Improve header structure with less processing overhead


2.3 How to enable ipv6 in nginx, openresty or kong?

First, check if your nginx/openresty/kong support ipv6:

nginx -V

Check if the result contains ipv6 support. If not, you need to rebuild nginx/openresty from source code with ipv6:

./configure  --prefix=/opt/nginx --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_gzip_static_module --with-ipv6

And for nginx 1.11.6+, you need not to do the above steps ,because:

Changes with nginx 1.11.5 11 Oct 2016

Change: the --with-ipv6 configure option was removed, now IPv6
   support is configured automatically.

Then you can enable nginx/openresty to listen to ipv6 addresses as follows: (Edit your nginx.conf)

listen       [::]:80 default_server;

In kong, you can enable ipv6 by editing your kong.conf as follows:

proxy_listen = 0.0.0.0:8000 reuseport backlog=16384, 0.0.0.0:8443 http2 ssl reuseport backlog=16384,[::]:8000

The [::]:8000 indicates that kong would listen to all interfaces’ 8000 port to service api requests.


3. Summary

In this post, I demonstrated how to enable ipv6 in nginx/openresty/kong . That’s it, thanks for your reading.

-->