【问题标题】:Getting a HTTPS connection to work with a local Rails app and nginx?获取 HTTPS 连接以使用本地 Rails 应用程序和 nginx?
【发布时间】:2013-03-19 14:30:30
【问题描述】:

我有一个在本地运行的 Ruby on Rails 应用程序。然后我也在本地运行一个 nginx 服务器。现在,通过 HTTP 连接可以正常工作,但是当我尝试通过 HTTPS 连接时,我从 nginx 收到“502 Bad Gateway”错误。我很确定证书工作正常,因为当它们没有工作时,我遇到了不同的错误,但现在我的 nginx 配置有问题?这是配置:

http {
  access_log off;
  #include mime.types;
  default_type application/octet-stream;

  upstream mydomain.com {
    server 127.0.0.1:8080;
  }

  server {
    listen 80;
    server_name local www.local;
    location / {
      proxy_pass http://mydomain.com;
    }
    add_header Pragma "no-cache";
  }

  server {
    listen 443;
    server_name local www.local;
    ssl on;
    ssl_certificate /Users/daise/projects/mydomain/run/ssl/server.crt;
    ssl_certificate_key /Users/daise/projects/mydomain/run/ssl/server.key;
    location / {
      proxy_set_header X-FORWARDED_PROTO https;

      #proxy_pass https://mydomain.herokuapp.com;
      proxy_pass https://mydomain.com;
    }
    add_header Pragma "no-cache";
  }
}

我还应该补充一点,我欺骗了我的 /etc/hosts 文件以解析为 127.0.0.1

【问题讨论】:

    标签: ruby-on-rails ssl https nginx


    【解决方案1】:

    改变

     proxy_pass https://mydomain.com;
    

     proxy_pass http://mydomain.com;
    

    您的 ssl 在 nginx 中终止。所以不需要使用https来连接上游服务器。

    [更多]

    还要注意您的配置文件中的错字:

    proxy_set_header X-FORWARDED_PROTO https
    

    proxy_set_header X-FORWARDED-PROTO https;
    

    【讨论】:

      猜你喜欢
      • 2013-10-29
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2021-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多