Configure Laravel on a subdomain with Nginx on Elastic Beanstalk

Viewed 392

My Laravel application runs locally and remotely on the main domain (https://www.example.com and https://example.com), but my staging environment doesn't work. The main page works, but other routes don't (I get a 504).

The nginx.conf I use is the following:

location / {
    try_files $uri $uri/ /index.php?$query_string;
    gzip_static on;
    if ($http_x_forwarded_proto = 'http'){
        return 301 https://$host$request_uri;
    }
}

How do I add https://staging.example.com to this configuration?

1 Answers

Since you are using Amazon Linux 2 (AL2), this could explain why your nginx config file is not used.

Specifically, on AL2 platforms, nginx config files should be set in .platform/nginx/conf.d/, not in .ebextensions. The nginx were setup using .ebextentions in AL1, but not in AL2.

Thus, you could try creating file .platform/nginx/conf.d/myconf.conf with the content:

location / {
    try_files $uri $uri/ /index.php?$query_string;
    gzip_static on;
    if ($http_x_forwarded_proto = 'http'){
        return 301 https://$host$request_uri;
    }
}

Please note, I can't verify whether the nginx config file is correct. It's just based on your question. It could also have mistakes.

Related