<p>As I previously answered, and as suggested by Brett Moore, this was indeed a database connectivity issue.</p>
<p>The DB timeout was being swallowed and logged to the filesystem, and the less helpful error that the primary site couldn't be found was surfaced to the UI.</p>

CC BY-SA 4.0
2024-06-20T22:36:32.847Z
2024-06-20T22:36:32.847Z
Zhaph - Ben Duguid
<p>I've been asked to deploy a Craft instance via an image in Azure Kubernetes Service, and I'm having a bit of an issue getting the site up and running - we're seeing a &quot;Site Not Found&quot; <code>SiteNotFoundException</code> when attempting to access the site.</p>
<p>I've set an environment variable <code>PRIMARY_SITE_URL</code> set to the required domain, and we're setting the <code>@web</code> alias based on that:</p>
<pre class="lang-php prettyprint-override"><code>'aliases' =&gt; [
  '@web' =&gt; rtrim(APP::env('PRIMARY_SITE_URL'), '/'),
  '@webroot' =&gt; dirname(__DIR__) . '/web',
]
</code></pre>
<p>However we're still seeing this issue - I assume this is because the setup we have includes a load balancer that's handling the initial request for us, and instead mapping the domain into the <code>x-forwarded-host</code> header of the request.</p>
<p>Checking the request headers with a small test service, the <code>Host</code> is the internal IP address (and port) of the AKS pod, and the originally requested domain (that's set in both <code>PRIMARY_SITE_URL</code> and <code>DEFAULT_SITE_URL</code>) is only on the <code>x-forwarded-host</code> header.</p>
<p>I assume I'm getting the SiteNotFound exception because the value on the host (IP and Port) doesn't match the value set in the Environment variable? Is there any way to get Craft to read the <code>x-forwarded-host</code> value when trying to match the request.</p>

CC BY-SA 4.0
2024-06-11T17:15:22.793Z
Looks like this is more a database connectivity error, rather than a `PRIMARY_SITE_URL` issue - working with the hosting team, logs are showing DB timeouts rather than anything else.
Zhaph - Ben Duguid
CC BY-SA 4.0
2024-06-11T18:00:42.677Z
Can you connect to the database server within the container? This error can be the result of numerous things but it is most likely a database connectivity issue.
Brett Moore
CC BY-SA 4.0
2024-06-20T22:32:36.397Z
Sorry @BrettMoore, at the point I raised this and my answer (that's now a comment) the application couldn't reach the database at all, no. But the DB timeout was swallowed and I just had the "Primary Site Not Found" error raised instead.
Zhaph - Ben Duguid
<craft4><load-balancer>
Site not found error when running Craft CMS behind a loadbalancer in a container
# Site not found error when running Craft CMS behind a loadbalancer in a container

(Asked by: username_0 on 2024-06-04)

I've been asked to deploy a Craft instance via an image in Azure Kubernetes Service, and I'm having a bit of an issue getting the site up and running - we're seeing a "Site Not Found" SiteNotFoundException when attempting to access the site.
I've set an environment variable PRIMARY_SITE_URL set to the required domain, and we're setting the @web alias based on that:
'aliases' => [
  '@web' => rtrim(APP::env('PRIMARY_SITE_URL'), '/'),
  '@webroot' => dirname(__DIR__) . '/web',
]

However we're still seeing this issue - I assume this is because the setup we have includes a load balancer that's handling the initial request for us, and instead mapping the domain into the x-forwarded-host header of the request.
Checking the request headers with a small test service, the Host is the internal IP address (and port) of the AKS pod, and the originally requested domain (that's set in both PRIMARY_SITE_URL and DEFAULT_SITE_URL) is only on the x-forwarded-host header.
I assume I'm getting the SiteNotFound exception because the value on the host (IP and Port) doesn't match the value set in the Environment variable? Is there any way to get Craft to read the x-forwarded-host value when trying to match the request.

**Tags:** craft4, load-balancer
> **Comments:**
> **username_0**: Looks like this is more a database connectivity error, rather than a `PRIMARY_SITE_URL` issue - working with the hosting team, logs are showing DB timeouts rather than anything else.  
> **username_1**: Can you connect to the database server within the container? This error can be the result of numerous things but it is most likely a database connectivity issue.  
> **username_0**: Sorry @BrettMoore, at the point I raised this and my answer (that's now a comment) the application couldn't reach the database at all, no. But the DB timeout was swallowed and I just had the "Primary Site Not Found" error raised instead.  

---

## 1 answers

### Answer by username_0 on 2024-06-20. Score: 0 | Accepted answer

As I previously answered, and as suggested by Brett Moore, this was indeed a database connectivity issue.

The DB timeout was being swallowed and logged to the filesystem, and the less helpful error that the primary site couldn't be found was surfaced to the UI.


---

