laravel - 在 Elastic Beanstalk 上使用 Nginx 在子域上配置 Laravel

标签 laravel nginx amazon-elastic-beanstalk

我的 Laravel 应用程序在主域( https://www.example.comhttps://example.com )上本地和远程运行,但我的暂存环境不起作用。主页有效,但其他路由无效(我收到 504)。

我使用的nginx.conf如下:

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

如何添加 https://staging.example.com到这个配置?

最佳答案

由于您使用的是 Amazon Linux 2 (AL2),这可以解释为什么未使用您的 nginx 配置文件。

具体来说,在 AL2 平台上,nginx 配置文件 should be set.platform/nginx/conf.d/ 中,而不是在 .ebextensions 中。 nginx 是在 AL1 中使用 .ebextentions 设置的,但在 AL2 中不是。

因此,您可以尝试使用以下内容创建文件 .platform/nginx/conf.d/myconf.conf:

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

请注意,我无法验证 nginx 配置文件是否正确。这只是基于你的问题。它也可能有错误。

关于laravel - 在 Elastic Beanstalk 上使用 Nginx 在子域上配置 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63001287/

相关文章:

laravel - '包 zendframework/zend-diactoros 被放弃,你应该避免使用它。使用 laminas/laminas-diactoros 代替。

laravel中的sql注入(inject)预防

php - 类似于 Facebook 搜索的 Laravel 原始全文查询

php - 引导导航栏事件元素选项?

java - 域名+nginx+tomcat设置

django - 编辑 urls.py 需要重新启动网络服务器吗?

ssl - 将我的站点 cert.key 和 cert.pem 放在 Nginx Docker 容器中是一种好习惯吗?

amazon-web-services - 指向新实例的 AWS 弹性 IP 不起作用

amazon-web-services - Golang 和 AWS : Deployment to AWS Elastic Beanstalk not working

java - 使用 Elastic Beanstalk 上的 catalina.out 缓解存储问题