Enabling IPv6 on your Laravel Forge Webserver
January 21, 2016
It's 2016 and the world is running on a very low supply of IPv4 addresses. Officially ARIN (American Registry for Internet Numbers) has given out it's last block of IPv4 addresses. So what are we to do?
Well a long time ago IPv6 was introduced. Which provides 340,282,366,920,938,463,463,374,607,431,768,211,456 possible addresses. That's more than enough for the foreseeable future. It also removes the need for complex/buggy network technology like NAT which can slow connections. So how do you go about enabling IPv6 traffic on your web servers? Specifically your servers you have generated on Laravel Forge?
Enabling IPv6 on your server
Well the first thing you'll need to do is check that your server is actually setup to handle the IPv6 connection. If you're using Linode (with the network helper enabled) you should already be good to go. If not follow this tutorial. If you're using Digital Ocean you'll want to make sure that IPv6 is enabled in your network information. If it's not already, you'll want to enable it using this tutorial. Thankfully, if you have created your droplet after January 8th, 2016 Forge should have enabled and configured it for you automatically. If you're using AWS you're shit out of luck until Amazon finally supports IPv6.
Setting up your DNS
Once you have set up your server to accept the incoming IPv6 connections you'll want to setup your dns server with a AAAA record. This is similar to the A record you already have but is specifically for IPv6 addresses. You'll get the v6 address from your provider (Digital Ocean or Linode) under their respective networking tabs. Paste this in your DNS configuration, give it a few minutes to propagate and you can move on to the next step!
Enabling IPv6 for your Forge sites
Now we've gotten to the easy part. After you have completed the steps above all you have to do is enable IPv6 on each site. To do so go to the site configuration on Forge and click the "Edit Files > Edit Nginx Configuration" menu in the lower right hand corner (shown below).
When you see the configuration screen you'll want to find the line that says
and add a line below it so it looks like this.
listen 80; listen [::]:80;
What you're telling the server there is to listen on the default IPv4 port (the first line) and on the second line to listen on the IPv6 port.
If you have SSL enabled you'll want to do the same thing for the top (the redirect from port 80 to port 443.
as well as add it to the second server block containing the SSL/TLS configuration. You'll want to do the same thing we did above for port 443 this time.
listen 443 ssl; listen [::]:443 ssl;
Testing and Debugging
If you don't have IPv6 available from your ISP you'll want to test the connection from a third party service. I have found this site to be useful http://ipv6-test.com/validate.php (just ignore the IPv6 only DNS as most providers are not enabled yet). If you do have an IPv6 connection enabled through your ISP you might be interested in seeing which site's are being loaded via IPv6. For that I recommend the Website IP plugin for Google Chrome that shows the IP in a small box at the bottom of each page when it's enabled.
If all checks out, you're done and can repeat the above steps for all of your websites.