Enable IPv6 connectivity for Nginx

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, March 15, 2012

Follow me on Twitter as @mattiasgeniar

Enabling IPv6 connectivity in Nginx is very easy, providing you already have a valid IPv6 connection/IP on your server. You should normally already have a configuration as follows.

server {
        listen          80;
        server_name     a.b.c;
}

First, verify that your nginx is configured for IPv6.

# nginx -V
... --with-ipv6 ...

Now, you can change your nginx configuration file to enable IPv6. To create server-block that listens on all available IPv6 IPs as well as IPv4, add this.

server {
        listen          :80;
        listen          [::]:80;
        server_name     a.b.c;
}

If you want a server-block that only listens on IPv6 and not IPv4, make use of the ipv6only flag.

server {
        listen          [::]:80 ipv6only=on;
        server_name     a.b.c;
}

Binding IPv6 on a single IP can also be done as such.

server {
        listen          [2a03:a800:2:1::1]:80 ipv6only=on;
        server_name     a.b.c;


Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.