Nginx: Configure and Install With IPv6 Networking Support

by on July 22, 2010 · 2 comments· LAST UPDATED July 22, 2010

in

How do I configure IPv6 networking under nginx? How do I assign and use an IPv6 address under nginx web server? How do I enable IPv6 Support in nginx?

You can easily configure IPv6 under nginx as follows. First, make sure IPv6 networking is working properly. See IPv6 CentOS / RHEL, FreeBSD, Debian / Ubuntu Linux, and Novell Suse/OpenSUSE Linux network configuration for more info.

Compile Nginx With IPv6 Support

You need to pass the --with-ipv6 option to configure command. Type the following command to compile it, enter:
# cd /path/to/nginx-src-code/
# ./configure --without-http_autoindex_module --without-http_userid_module \
--without-http_auth_basic_module --without-http_geo_module \
--without-http_fastcgi_module --without-http_empty_gif_module \
--with-poll_module --with-http_stub_status_module \
--with-http_ssl_module --with-ipv6
# make install

Verify the same with the following command:
# /usr/local/nginx/sbin/nginx -V
Sample outputs:

nginx version: nginx/0.8.46
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments: --without-http_autoindex_module --without-http_userid_module --without-http_auth_basic_module --without-http_geo_module --without-http_fastcgi_module --without-http_empty_gif_module --with-poll_module --with-http_stub_status_module --with-http_ssl_module --with-ipv6

Make sure you pass options as per your setup.

Edit Configuration File

Edit /usr/local/nginx/conf/nginx.conf, enter:
# vi /usr/local/nginx/conf/nginx.conf
Make sure listen directive is updated as follows (this must be placed between server { ... } ) :

 
# listen to all IPv4 and IPv6 interfaces:
# ipv4
listen :80;
# ipv6
listen [::]:80;
 

Reload and restart nginx configuration, enter:
# /usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx -s reload

How Do I Listen Only On 2607:f0d0:1002:59::2?

Edit config file as follows:
listen listen [2607:f0d0:1002:59::2]:80;

How Do I Verify IPv6 and IPv4 Both Are Working?

Use the netstat command to verify ip binding:
# netstat -tulpna | grep nginx
Sample outputs:

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      33094/nginx
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      33094/nginx
tcp        0      0 :::80                       :::*                        LISTEN      33094/nginx

The last line indicates that IPv6 and first two line indicate HTTP and HTTPS connection for IPv4. You can also use the wget command or a web browser to verify the same:
$ wget http://[2607:f0d0:1002:59::2]/

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 2 comments… read them below or add one }

1 Southafrica August 11, 2010 at 10:21 am

Hi,

is NGINX able to acct as a reverseproxy and send client requests to backendserver with IPV6-adresses (client -> IPV4 -> NGINX -> IPV6 -> backendserver)?

Greetings

Reply

2 George March 20, 2013 at 9:48 pm

I’m running Ubuntu 12.10, and having both listen statements prevented ngnix from starting. The second listen statement binds both IPv4 and IPv6. Removing the first statement will show IPv4 address as mapped address in log files. Adding “ipv6only=on” to the seconds listen statement will prevent this and enable listening on IPv4 and IPv6. More details: http://serverfault.com/questions/489843/ngnix-startup-isse-ipv4-ipv6/489847

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: