<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Nginx &#8211; Wade Tregaskis</title>
	<atom:link href="https://wadetregaskis.com/tags/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>https://wadetregaskis.com</link>
	<description></description>
	<lastBuildDate>Tue, 23 Jan 2024 01:03:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wadetregaskis.com/wp-content/uploads/2016/03/Stitch-512x512-1-256x256.png</url>
	<title>Nginx &#8211; Wade Tregaskis</title>
	<link>https://wadetregaskis.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">226351702</site>	<item>
		<title>cloudinit breaks connections from localhost to Plesk-operated web servers</title>
		<link>https://wadetregaskis.com/cloudinit-breaks-connections-from-localhost-to-plesk-operated-web-servers/</link>
					<comments>https://wadetregaskis.com/cloudinit-breaks-connections-from-localhost-to-plesk-operated-web-servers/#respond</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Tue, 23 Jan 2024 01:03:08 +0000</pubDate>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Broken Link Checker]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[cloud-init]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Plesk Obsidian]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://wadetregaskis.com/?p=7491</guid>

					<description><![CDATA[I don&#8217;t know how or why it is even installed &#8211; perhaps part of the provided Ubuntu image from my VPS host &#8211; but cloud-init (a.k.a &#8220;cloud-config&#8221;) is a bit obnoxious. At [re]boot time (best I can tell), it resets /etc/hosts based on some random template it has (/etc/cloud/templates/hosts.debian.tmpl in my case, even though that&#8230; <a class="read-more-link" href="https://wadetregaskis.com/cloudinit-breaks-connections-from-localhost-to-plesk-operated-web-servers/" data-wpel-link="internal">Read more</a>]]></description>
										<content:encoded><![CDATA[
<p>I don&#8217;t know how or why it is even installed &#8211; perhaps part of the provided Ubuntu image from my VPS host &#8211; but <a href="https://github.com/canonical/cloud-init" data-wpel-link="external" target="_blank" rel="external noopener">cloud-init</a> (a.k.a &#8220;cloud-config&#8221;) is a bit obnoxious.  At [re]boot time (best I can tell), it resets <code>/etc/hosts</code> based on some random template it has (<code>/etc/cloud/templates/hosts.debian.tmpl</code> in my case, even though that makes no sense as I&#8217;m not using Debian).  That template has a very weird entry:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><code>127.0.1.1 {{fqdn}} {{hostname}}</code></p>
</blockquote>



<p>I have no idea what it&#8217;s even trying to do with that.</p>



<p>What it <em>does</em> do is break a lot of things, because while 127.0.1.1 is a valid address (albeit weird to use instead of the canonical 127.0.0.1), in a standard <a href="https://www.plesk.com" data-wpel-link="external" target="_blank" rel="external noopener">Plesk</a> system <a href="https://nginx.org" data-wpel-link="external" target="_blank" rel="external noopener">Nginx</a> (that sits in front of <a href="https://httpd.apache.org" data-wpel-link="external" target="_blank" rel="external noopener">Apache</a> typically) is configured to listen only on the network interface(s) associated with your web server&#8217;s public IP address(es), not localhost<sup data-fn="f02da440-1755-49a0-b849-7989472e1805" class="fn"><a href="#f02da440-1755-49a0-b849-7989472e1805" id="f02da440-1755-49a0-b849-7989472e1805-link">1</a></sup>.  So if you try e.g. <code>curl mydomain.com</code> from inside your server hosting that very domain, you get a connection refused error (or it just times out with no response, depending on firewall settings).</p>



<p>The way <a href="https://talk.plesk.com/threads/can-no-longer-connect-to-nginx-from-localhost.372659/" data-wpel-link="external" target="_blank" rel="external noopener">I found out about this</a> was when WordPress&#8217;s &#8220;cron&#8221; system silently stopped running tasks (because I use a real cron job to trigger it periodically, rather than relying on WordPress&#8217;s flaky built-in system).  I subsequently also noticed that <a href="https://wordpress.org/plugins/broken-link-checker/" data-wpel-link="external" target="_blank" rel="external noopener">Broken Link Checker</a> mistakenly reported <em>every</em> link within my own site as broken.</p>



<h2 class="wp-block-heading">The solution</h2>



<p>…is fairly simple &#8211; modify the template to remove the offending line.  You then have to either reboot or similarly manually modify <code>/etc/hosts</code> to actually apply the fix.</p>



<p>If for some reason you cannot do that, there are potentially workarounds.  For example, for <code>curl</code> commands you can make <code>curl</code> navigate around the problem this like:</p>



<figure class="wp-block-pullquote"><blockquote><p><code>curl --header 'Host: mydomain.com' https://&lt;your server's external IP></code></p></blockquote></figure>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>☝️ If you have a CDN or similar in front of your server, e.g. <a href="https://www.cloudflare.com/" data-wpel-link="external" target="_blank" rel="external noopener">Cloudflare</a>, this will potentially behave differently to connecting from another host; it&#8217;ll bypass the CDN and connect directly to your web server (effectively the same as if you did connect to 127.0.0.1).</p>



<p>Depending on your needs, this could be desirable (e.g. no need to send WordPress cron invocations through a CDN) or undesirable (broken link checking probably should go through the CDN, just like all real traffic, to test that the CDN doesn&#8217;t cause a problem).</p>
</div></div>



<p>In a non-Plesk environment you might also be able to just change the Nginx configuration (somewhere under <code>/etc/nginx</code>).  That&#8217;s ill-advised for Plesk-operated servers as Plesk will inevitably revert your changes (and as far as I can tell there is no configuration option, or workaround otherwise, to make Plesk configure Nginx to listen on localhost as well 😕).</p>


<ol class="wp-block-footnotes"><li id="f02da440-1755-49a0-b849-7989472e1805">I suspect this is more a side-effect than intentional.  Plesk chooses the interface only implicitly, when it specifies that it listens on specific addresses &#8211; those assigned to the website in question (Nginx can host multiple otherwise unrelated websites, and each is configured independently within its settings).  Since Plesk supports hosting multiple websites, each with potentially <em>different</em> IP addresses, it makes sense that it would want to keep them separate.  Otherwise, in a shared hosting situation you could connect to the IP address for somehost.com yet issue a HTTP request for unrelatedhost.com and actually get a response, which is weird, at least. <a href="#f02da440-1755-49a0-b849-7989472e1805-link" aria-label="Jump to footnote reference 1">↩︎</a></li></ol>]]></content:encoded>
					
					<wfw:commentRss>https://wadetregaskis.com/cloudinit-breaks-connections-from-localhost-to-plesk-operated-web-servers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7491</post-id>	</item>
	</channel>
</rss>
