首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹性beanstalk nginx重定向设置不起作用

弹性beanstalk nginx重定向设置不起作用
EN

Stack Overflow用户
提问于 2017-08-21 18:05:59
回答 1查看 388关注 0票数 0

我正在尝试将http重定向到https,并且我有这样的配置:

代码语言:javascript
复制
files:
    "/etc/nginx/conf.d/robots.conf":
        mode: "000544"
        owner: root
        group: root
        content: |
            server {
                listen 80;

                server_name example.com;

                location =/health {
                    return 200 "health-check";
                }

                location / {
                    if ($http_x_forwarded_proto != "https") {
                        return 301 https://$host$request_uri;
                    }
                }
            }
            server {
                listen 80 default_server;

                server_name www.example.com;

                location =/health {
                    return 200 "health-check";
                }

                location / {
                    if ($http_x_forwarded_proto != "https") {
                        return 301 https://$host$request_uri;
                    }
                }
            }

但当我转到http://example.comhttp://www.example.com时没有重定向...我尝试了多种设置,但似乎从未完全正常工作过。

EN

回答 1

Stack Overflow用户

发布于 2017-08-21 18:17:38

要做到这一点,最好的方法是如下设置您的配置

代码语言:javascript
复制
server {
       listen         80;
       server_name    my.example.com;
       return         301 https://$server_name$request_uri;
}

server {
       listen         443 ssl;
       server_name    my.example.com;
       # add Strict-Transport-Security to prevent man in the middle attacks
       add_header Strict-Transport-Security "max-age=31536000"; 

       [....]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45794392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档