Nginx + IPv6

    Recently I wrote a topic about IPv6 support in Windows 7 / Vista / XP (it's here ). I wanted to make IPv6 support on my server, where sites are hosted, in the end, this is what happened.

    My server is under FreeBSD, I used HE.net to get the IPv6 address on the server, here is the config for configuring this tunnel in /etc/rc.conf :

    ipv6_gateway_enable="YES"
    ipv6_enable="YES"
    gif_interfaces="gif0"
    gifconfig_gif0="ВАШ_IP_СЕРВЕРА 72.52.104.74"
    ipv6_ifconfig_gif0="2001:470:1f04:***::2"  #Выданный вам IPv6
    ipv6_defaultrouter="2001:470:1f04:***::1" #Это адрес сервера HE.net в IPv6.
    

    Now the question arose about support for the web server, IPv6 addressing. I use the nginx + apache 2.2 bunch, here is the server excerpt in the nginx config:

    server {
        listen 80 default;
        listen [::]:80 default;
        server_name _;
            location /nginx_status {
                    stub_status on;
                    access_log   off;
                    allow all;
            }
        location / {
            proxy_pass http://127.0.0.1:81;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size       10m;
            client_body_buffer_size    128k;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
            proxy_send_lowat           12000;
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
             }
            location ~* \.(jpeg|jpg|gif|png|css|js|pdf|txt|tar|tar.gz|zip|ico|swf|rss)$ {
                    root /usr/local/www/static/$host;
                    access_log off;
                    expires off;
                    }
    }
    

    As you can see, the string listen [::] was added : 80 default; . This will enable your nginx to listen to all IPv6 addresses.

    By default, such an entry can be added to one server section. This implies, probably, that in IPv6 each site will be on its IPv6 address.

    In order for each server {} to have its own IPv6 address, you need to add listen [2001: 470: 1f04: *** :: 3]: 80 . Naturally, you need to cling to such addresses alias for your main interface.

    Then you need to make an entry in the DNS of your domains that are hosted.

    I made this entry:

    *                 IN               AAAA             2001:470:1f04:***::2
    

    Because I have all the domains on one server and I didn’t bother with issuing IPv6 to each site, I just did it:

    IPv6 Network -----------> IPv6 ServerIP ---------> proxying to 127.0 .0.1 IPv4 (where Apache runs with the usual IPv4 settings).

    In total, having registered this, I got the availability of all my domains from the IPv6 network.

    For each domain in ServerAlias, Apache registered a subdomain ipv6.domain_name.ru. Well, I created symbolic links for the domain in my construction (see root / usr / local / www / static / $ host;). In this folder I have symbolic links for all domains and subdomains on my server.

    PS Most hosting providers and hosting panels would support IPv6 out of the box. Most domains could work there and there, then the transition to IPv6 would not be so painful.

    PS IPv6 traffic appeared on sites, probably due to the addition of sites that support IPv6 to directories.

    Also popular now: