<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Agustin Romano on Medium]]></title>
        <description><![CDATA[Stories by Agustin Romano on Medium]]></description>
        <link>https://medium.com/@aguromano?source=rss-22a6765ce73d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8gjR8MPU1iLhTDE0LDtOtw.png</url>
            <title>Stories by Agustin Romano on Medium</title>
            <link>https://medium.com/@aguromano?source=rss-22a6765ce73d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 19:18:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aguromano/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Naked Domain redirect to www with kubernetes nginx]]></title>
            <link>https://medium.com/devgurus/naked-domain-redirect-to-www-with-kubernetes-nginx-1000969b9046?source=rss-22a6765ce73d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1000969b9046</guid>
            <category><![CDATA[domains]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Agustin Romano]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 20:50:24 GMT</pubDate>
            <atom:updated>2018-08-28T12:35:28.853Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>Here at <a href="https://www.devgurus.io/">DevGurus.io</a>, one of our customers had the following setup:</p><ul><li>DNS records managed in GoDaddy</li><li>3 DNS A records with “@” name and with Google IPs value (216.239.32.21, 216.239.34.21, 216.239.36.21). Usually these are set when Google Suite or Google Cloud Service is configured for a Domain (more information <a href="https://support.google.com/a/answer/48090">here</a>). These are the IP´s you would get if you do a nslookup example.com</li><li>website was actually in “www” subdomain, with a CNAME record pointing to a url from CDN provider. This means, when you access www.example.com you are actually accessing something like url-from-cdn.cdnprovider.com or whatever URL your CDN provider gives. Here if you do a nslookup www.example.com you would get something like this:</li></ul><pre>#nslookup www.example.com</pre><pre>Non-authoritative answer:<br>www.example.com canonical name = url-from-cdn.cdnprovider.com.<br>Name: url-from-cdn.cdnprovider.com<br>Address: 11.22.33.44</pre><p>Noticed canonical name ? That’s actually CNAME</p><p>So, if final users try to access the site with any possible combination:</p><ol><li><a href="http://example.com/">http://example.com</a></li><li><a href="http://www.example.com/">http://www.example.com</a></li><li><a href="https://example.com/">https://example.com</a></li></ol><p>It should be redirected to <a href="https://www.example.com/">https://www.example.com</a> (this would technically be possibility #4).</p><h3>Problem</h3><p>Option #1 works, since there is a 301 redirection in place (this comes from Google, notice “Server: ghs”):</p><pre>#curl -I example.com<br>HTTP/1.1 301 Moved Permanently<br>Location: http://www.example.com<br>Date: Wed, 15 Aug 2018 18:27:55 GMT<br>Content-Type: text/html; charset=UTF-8<br>Server: ghs<br>Content-Length: 234<br>X-XSS-Protection: 1; mode=block<br>X-Frame-Options: SAMEORIGIN</pre><p>Option #2 works, since subdomain www actually takes you to CDN, and in there we have an enforcement to redirect you to https if you are coming from http .</p><p>But the problem is in #3:</p><pre>#curl -I https://example.com<br>curl: (7) Failed to connect to example.com port 443: Operation timed out</pre><p>If you try to browse it, you would get site can&#39;t be reached error.</p><h3>Alternatives</h3><h4>Google / G-Suite / Google Domain</h4><p>Since the A records are currently pointing to Google IPs, our first option was to change settings there, to update that 301 Redirect rule for HTTPS, and upload our SSL Certificate to enable 443 port.</p><p>Unfortunately we found no way of doing that, so we analyze the following alternative.</p><h4>GoDaddy</h4><p>Currently GoDaddy does not offer ALIAS DNS record, and we cannot setup CNAME for Naked Domain because of <a href="http://www.faqs.org/rfcs/rfc1034.html">RFC1034</a> (section 3.6.2).</p><blockquote>An ALIAS record is a virtual record type, which we could say is kinda a mixture of A and CNAME, where following our example, we could add a record for the naked domain example.com to url-from-cdn.cdnprovider.com and if we do a nslookup example.com we would see the ip from url-from-cdn.cdnprovider.com . So its like having an A record, that automatically updates the IP value.</blockquote><p>However, they do offer a Forwarding section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*ffqCBFA-4soRgIt9ZK96ow.png" /></figure><p>While applying this, the A records get removed and only 1 A record is added, with an IP from GoDaddy. But we get almost same results than before:</p><pre>#curl -I example.com<br>HTTP/1.1 301 Moved Permanently<br>Server: nginx/1.12.2<br>Date: Thu, 16 Aug 2018 18:10:16 GMT<br>Content-Type: text/html; charset=utf-8<br>Connection: close<br>Location: <a href="https://www.example```/">https://www.example</a></pre><pre>#curl -I https://example.com<br>curl: (7) Failed to connect to https://example.com  port 443: Operation timed out<br></pre><blockquote>Note: After several support contact with GoDaddy, they are not able to add our SSL Cert (which we bought it from them), which would solve the issues. And yes, they use a nginx as well.</blockquote><h4>A Record with IP from CDN</h4><p>Technically, what we could do, is create an A record with the IP we got from CDN Provider, 11.22.33.44. This might work, but it’s not recommended at all…because we don’t have control at all of that IP. If our CDN provider changes that IP, we will have to manually update the A Record, with downtime until we do it and propagates.</p><h3>Solution</h3><p>We ended up deploying our own nginx server in our GCP Kubernetes Cluster, with a STATIC IP Address we reserve in GCP, which we have control and we know it won’t change.</p><blockquote>Note: You could opt for the Cloud Provider/Source Repository/CI of your choice</blockquote><p>We will try to sum up the steps we did to deploy the solution:</p><ol><li>Get the latest helm chart for <a href="https://github.com/helm/charts/tree/master/stable/nginx-ingress">nginx-ingress</a> (we like to use Helm, as you can see in the <a href="https://github.com/helm/charts/blob/master/stable/nginx-ingress/Chart.yaml">chart.yaml</a> file the source is <a href="https://github.com/kubernetes/ingress-nginx">kubernetes/ingress-nginx</a>)</li><li>We use Bitbucket as source repository with Bitbucket pipelines as CI, so we created a new repository for this.</li><li>We reserve an <a href="https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address">static IP in GCP</a> that we are going to use in the nginx controller service (LoadBalancer type). <strong>IMPORTANT: </strong>This IP needs to be regional, and in same region than the GKE Cluster.</li><li>Your helm customization file should look something like this:</li></ol><pre>controller:<br>  service:<br>    loadBalancerIP: 123.45.67.89<br>    externalTrafficPolicy: Local<br>  replicaCount: 2</pre><pre>ingress:<br>  enabled: true<br>  annotations:<br>      nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;<br>      nginx.ingress.kubernetes.io/configuration-snippet: |<br>        if ($http_x_forwarded_proto != &#39;https&#39;) {<br>          return 301 <a href="https://www.$host$request_uri/">https://www.$host$request_uri</a>;<br>        }</pre><pre>tls:<br>    - hosts:<br>      - example.com<br>      secretName: secret-with-tls<br>  <br>  rules:<br>  - host: example.com<br>    http:<br>      paths:<br>      - backend:<br>          serviceName: default-backend<br>          servicePort: 80<br>        path: /</pre><p>Being 123.45.67.89 the IP reserved in step #4. You need to specify either a rule or backend, even though it will not route it there because the redirection happens before.</p><p>There are many other options/features you could enable/configure. Either if you want a different redirection, or if you don’t want to redirect maintaining the request_uri …anything that matches your needs!</p><p>5. Once this is successfully deployed, you could test functionality using curl:</p><pre>curl -Ik https://123.45.67.89 -H &#39;Host: example.com&#39;<br>HTTP/2 301<br>server: nginx/1.13.12<br>date: Thu, 16 Aug 2018 18:24:00 GMT<br>content-type: text/html<br>content-length: 186<br>location: https://www.example.com</pre><p>And also validate, that is including the request_uri :</p><pre>curl -Ik https://123.45.67.89/login -H &#39;Host: example.com&#39;<br>HTTP/2 301<br>server: nginx/1.13.12<br>date: Thu, 16 Aug 2018 18:24:00 GMT<br>content-type: text/html<br>content-length: 186<br>location: https://www.example.com/login</pre><p>7. Once you finished validation, you are ready to update the A record in your DNS, using the IP we got from step #4.</p><p>8. Once DNS propagation is over (we recommend setting a small value, in GoDaddy you could set it to <em>600 seconds</em> )</p><p>And thats it!</p><p>Hope you found this article useful, please feel free to comment</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1000969b9046" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devgurus/naked-domain-redirect-to-www-with-kubernetes-nginx-1000969b9046">Naked Domain redirect to www with kubernetes nginx</a> was originally published in <a href="https://medium.com/devgurus">Devgurus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>