When I recently migrated from Apache to Nginx I temporarily broke the ability of IPv6 clients to reach my website. Last night I spent a few minutes updating the Nginx configuration to support IPv6. Since I’m using virtual hosts on a single CentOS 6.3 server I had to make a few configuration tweaks to the Nginx config files. Thankfully Linode fully supports IPv6 so there was very little to-do outside of the actual web server configuration.
The adoption of IPv6 is growing slowly but promises to accelerate significantly with the depletion of the IPv4 address pools. You can check out Google’s statistics which indicate that more than 1% of all Internet traffic to Google is now IPv6 as opposed to the legacy IPv4. In June 2011 Chandler Harris from Information Week didn’t believe that the IPv4 exhaustion was spuring IPv6 adoption. I think that Chandler was just a little too early in his predictions. While all the IPv4 address pools had been allocated the pools themselves weren’t actually exhausted. Looking at the Google statistics you can quickly see that Romania is leading the IPv6 adoption race at 8.91% followed by France at 5.1% and the United States at 2.17%.
Here are the steps I took to enable IPv6 support within Nginx.
You first need to confirm that Nginx was compiled with IPv6 support. You can do that with the following command; nginx -V. If Nginx was compiled with IPv6 support you should find the following in the output –with-ipv6.
In the default Nginx configuration file (/etc/nginx/conf.d/default.conf) I replaced the listen 80 default_server; with listen [::]:80 default_server;
I also had to modify each of my virtual host configuration files adding listen [::]:80; to each.
In the end I ended up with files that look like this;
default.conf
# # The default server # server { listen [::]:80 default_server; server_name _; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
blog.michaelfmcnamara.com.conf
server { # Tell nginx to handle requests for the www.yoursite.com domain listen [::]:80; server_name blog.michaelfmcnamara.com mirror.michaelfmcnamara.com; index index.php index.html index.htm; ... ... }
You can test your website at IPv4 and IPv6 availability at ipv6-test.com.
Cheers!