<p>I figured out a solution, though I'm not totally clear why it works.</p>

<p>Adjusting the server statement below</p>

<pre><code>server {
    listen 80;
    listen [::]:443 ssl;
    ...
</code></pre>

<p>to read </p>

<pre><code>server {
    listen 80;
    listen 443 ssl;
    listen [::]:443 ssl;
    ...
</code></pre>

<p>Solved my problem and allowed my load balancer to direct to my application servers.</p>

CC BY-SA 4.0
2020-04-17T14:52:32.600Z
2020-04-17T16:25:09.520Z
2020-04-17T16:25:09.520Z
Johnronomous Bosch
<p>I'm attempting to set up a load balancing set up on laravel forge for a craft site.
I have one server that is provisioned as a load balancer, two app servers both set up to server the same craft install (deployed from the same Git Repo) and one db server. </p>

<p>The two app servers are configured to use the db server in the env file. I have tested hitting both app servers by adjusting my host and can confirm that each loads the Craft site as expected. I've put up a firewall to only accept traffic on port 80 from the private IP of the load balancer.</p>

<p>My load balancing server is configured to network with the app servers. The load balancer is set up with SSL (let's encrypt).</p>

<p>The issue I'm seeing seems to be in the SSL redirect Laravel Forge sets up. After configuring SSL I get a bad gateway error when I load the site.
Here is my nginx config for the load balancer </p>

<pre><code># FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/before/*;

# FORGE CONFIG (DO NOT REMOVE!)
include upstreams/mydomain.com;

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name mydomain.com;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/mydomain.com/774031/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain.com/774031/server.key;

    ssl_protocols TLSv1.2;

    charset utf-8;

    access_log off;
    error_log  /var/log/nginx/backtowork-ri.com-error.log error;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/backtowork-ri.com/server/*;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass https://1013240_app/;
        proxy_redirect off;

        # Handle Web Socket Connections
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/after/*;

</code></pre>

<p>if I adjust the config to listen on port 80 and 443 like so</p>

<pre><code>server {
    listen 80;
    listen [::]:443 ssl;
    ...
</code></pre>

<p>I see a too many redirects error.</p>

<p>I'm really not sure what I'm doing wrong. Any one have any thoughts?</p>

<nginx>
Setting up load balancing for Craft on Laravel Forge
# Setting up load balancing for Craft on Laravel Forge

(Asked by: username_0 on 2020-04-16)

I'm attempting to set up a load balancing set up on laravel forge for a craft site.
I have one server that is provisioned as a load balancer, two app servers both set up to server the same craft install (deployed from the same Git Repo) and one db server. 
The two app servers are configured to use the db server in the env file. I have tested hitting both app servers by adjusting my host and can confirm that each loads the Craft site as expected. I've put up a firewall to only accept traffic on port 80 from the private IP of the load balancer.
My load balancing server is configured to network with the app servers. The load balancer is set up with SSL (let's encrypt).
The issue I'm seeing seems to be in the SSL redirect Laravel Forge sets up. After configuring SSL I get a bad gateway error when I load the site.
Here is my nginx config for the load balancer 
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/before/*;

# FORGE CONFIG (DO NOT REMOVE!)
include upstreams/mydomain.com;

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name mydomain.com;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/mydomain.com/774031/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain.com/774031/server.key;

    ssl_protocols TLSv1.2;

    charset utf-8;

    access_log off;
    error_log  /var/log/nginx/backtowork-ri.com-error.log error;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/backtowork-ri.com/server/*;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass https://1013240_app/;
        proxy_redirect off;

        # Handle Web Socket Connections
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/after/*;


if I adjust the config to listen on port 80 and 443 like so
server {
    listen 80;
    listen [::]:443 ssl;
    ...

I see a too many redirects error.
I'm really not sure what I'm doing wrong. Any one have any thoughts?

**Tags:** nginx


---

## 1 answers

### Answer by username_0 on 2020-04-17. Score: 1

I figured out a solution, though I'm not totally clear why it works.
Adjusting the server statement below
server {
    listen 80;
    listen [::]:443 ssl;
    ...

to read 
server {
    listen 80;
    listen 443 ssl;
    listen [::]:443 ssl;
    ...

Solved my problem and allowed my load balancer to direct to my application servers.


---

