简体   繁体   中英

Configure Laravel on a subdomain with Nginx on Elastic Beanstalk

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM