1

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?

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.