【问题标题】:Nginx redirect url to secure domainNginx 将 url 重定向到安全域
【发布时间】:2018-06-21 04:29:25
【问题描述】:

我的 webstie 托管在 aws EC2 实例上,我有 nginx 1.12.2 和 Ec2 操作系统是 centos,我如何将 http://example.com 和 https://example.com 重定向到 https://www.example.com 。

谢谢

【问题讨论】:

  • 你在使用 aws route53 吗???
  • 不,我没有使用其他任何东西,只有我正在使用的这些东西。
  • 不,我没有使用其他任何东西,只有我正在使用的这些东西。我正在使用 Godaddy。
  • 你只是想在一个网址上显示 www 或者你想把它转发到另一个域?
  • 不仅想展示而且真的需要重定向上面我写的url。

标签: http nginx web https


【解决方案1】:

您将需要 3 个服务器部分(我几乎可以肯定您忘记处理 http://www.example.com 案例)

server {
    listen 80;
    server_name example.com; 
    location / {
             return 301 https://www.example.com$request_uri;
           }
...

server {
    listen 443 ssl; 
    server_name example.com;
    ssl_certificate ...
    location / {
             return 301 https://www.example.com$request_uri;
           }
...

server {
    listen 443 ssl; 
    server_name www.example.com;
    ssl_certificate ...
    location / {
             #your configuration here
           }
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 2015-12-14
    • 2012-12-03
    • 2021-11-03
    • 2011-09-19
    • 1970-01-01
    相关资源
    最近更新 更多