系统相关
首页 > 系统相关> > ruby-on-rails – 使用Rails 5应用程序生成Elastic Beanstalk Nginx上的502 Bad Gateway(太大标题)

ruby-on-rails – 使用Rails 5应用程序生成Elastic Beanstalk Nginx上的502 Bad Gateway(太大标题)

作者:互联网

我正在使用门卫并设计我的Rails 5应用程序来实现我自己的OAuth提供商,用于Amazon Alexa帐户链接.如果用户触发OAuth流程并且已经登录到我的网站,则流程正常.但是当用户未登录时,他需要先登录然后再开始流程.设计登录后,用户不会重定向到OAuth流程.我现在已经添加了在登录后重定向回OAuth流的功能,并且它在开发模式下工作正常(使用ngrok)但在生产中,我在登录后遇到502错误,我无法弄清楚问题是什么.

以下是access.log中的条目:

2017/05/03 22:54:04 [error] 2866#0: *185513 upstream sent too big header while reading response header from upstream, client: 172.31.23.232, server: _, request: "GET /oauth/authorize?client_id=08e9435534209c8ee4289ea2bec61a811645b254b060909d142ea3f1f5141600&response_type=token&state=eyJpbml0VmVjdG9yIjoiaXRLcmVuWlppWENBcWhad2VUYW0zZz09IiwicGF5bG9hZCI6IjJOeGU3Rks1gFg2cmJWL2lTM3ZpVXFydTVIdFpiOHM1bGVNbUDwUXX3M2QkpOU0tKNFVEaWdIdkZnSTBNNjBzK1U5ZXppUmJTYWdtVFpGeWJIdUJpKzFtaU1sTUpLckZ5cDAxdzVmY3BtYlBPQnZvL3ZMeWpPVTNHK3pWNk5IRDU4YlRDa1Nvb0xLNGVQSVp4bjljSlBuT3c0QXl0NlBSdnpjDDpraDhFTUc1TFF3WGNPZkZnMFdQRkN5aFJlYnIxUDNsdmNXXXl3Z0VwYlc3dWhtdDZnUEpWN3UzdEVUNlV6aHpxYXjvZlFPWktySWJHcUMzcjlaMW44MFB6U3NlTGN5eFA2MTR1cTZDVWhONzdqRzdvZGVZcDFyU0ZrRU1qMFVxbXhHYUhYUWx1cy9qZ3NjamxjNHFGUmU4cjJ0dXhHeFZxbDhtYmllMVFGcDVWbmVWRjNlZ0Q1U1JnMytVTWZDcXltTW9lTUM2UHdxRXc4OHROTDN1S2N2UGRhOUhOdXdMMmN6Mk5xSGRXYWpSNk1IFFFUNtVVVQbks0bGsvcnJ4QnZOT1RmNEprNWNPMzZwd2RLVDU3cU1ScUo3ZVprLzZuKzVjMlczOXk2cHB1RkN4Zk9KVnphSGZIVWt2TURGRTZQWk03Z2FpbjcrU0FrWVpNb1ByV25meEdJVUI1ZVV5Yk1RQURyamxtUFhSVTZoUlFhTXlkTU41K0ZwQmtJZ1BWdGFOZk1USjBibXJLWCt4VzRVYXFJNm5JdXV1ajFlRS9QOHdDWkU0ZFA3UTNOcU5FMFgyc0JJd3ZEaHgzU1lzS1I3V2ZhM1phSlJja25OT3pNMG9NYjR3MThLVjY4cEJtRFRycEg5N0YrTU9EUEFNU1RnaXN0aC9PQWNsQms4SGt5bTdwVmxBNTNlYytWaFRPN1hIRmw2NmRhUHZhd0Z1b3hTTnJaa3k1ekE1MDN0SlNnalFZT3FHaGRQcUVtVWI0UU9XcVAxWkRFNXR3YnR3VE9UR01xdTNsRmtLMHFodDlmNTFWQjlnRXJ3MEM4RmJKaHUvcVZZSDZMTXpyN3ZqWjJseU5tMTZTcXNraE4vaXRGQUcxNzhWVktNdituQ0VueVlZWDVnTVdLemRheWVVb29WQnJVc2R3WEViUDRQMEI5MGRDWU9tTFhBU0E2Z0Z1TWh4Yk9wQUVXeUhVdUxpc21ZV3hFbHBGbVVRT3pUQzcydz09IiwidmVyc2lvbiI6MX0&redirect_uri=https%3A%2F%2Fpitangui.amazon.com%2Fspa%2Fskill%2Faccount-linking-status.html%3FvendorId%3DM3AP36Y8XL4DFZ HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/oauth/authorize?client_id=08e9435534209c8ee4289ea2bec61a811645b254b060909d142ea3f1f5141600&response_type=token&state=eyJpbml0VmVjdG9yIjoiaXRLcmVuWfpbSENBvWfad2VUYW0zZz09IiwicGF5bG9hZCI6IjJOeGU3Rks1TFg2cmJWL2lTM3ZpVXFydTVIdFpiOHM1bGDNbB1wI3M2QkpOU0tKNFVEaXdIdkZnSTBN

(值混淆但长度相同)

并从error.log:

2017/05/04 21:15:07 [error] 579#0: *204674 upstream sent too big header while reading response header from upstream, client: 172.31.23.232, server: _, request: "POST /users/sign_in HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/users/sign_in", host: "example.com", referrer: "https://example.com/users/sign_in"

正如您所看到的,请求很长,所以我尝试配置没有任何效果的large_client_header_buffers.然后在阅读了一些类似的问题之后,我尝试配置fastcgi_buffers和fastcgi_buffer_size以及代理缓冲区,也没有效果.我正在使用.ebextension文件来添加这些配置,如here所述,但实际上我没有找到一种方法来验证这些配置在部署之后是否在生产中实际生效.

以下是我在首次出现错误之前对门卫/设计所做的修改:

在resource_owner_authenticator块中的模型中保存返回Path:

  resource_owner_authenticator do
    account_link = AccountLink.create(return_to: request.fullpath)
    session[:return_to] = account_link.id

    current_user || warden.authenticate!(:scope => :user)
  end

如果存在,则重定向到after_sign_in_path_for方法中的已保存路径:

  def after_sign_in_path_for(resource)
    account_link_id = session[:return_to]

    if account_link_id
      account_link = AccountLink.find(account_link_id)

      if account_link
        session.delete(:return_to)

        account_link.return_to
      else
        dashboard_path
      end
    end
  end

我还看到了Elastic Beanstalk中的502s可能与未激活的SSL证书相关的建议,但我已经检查过了.

编辑:在我的rails生产日志中,我看到登录路径的帖子以及之后的302重定向都是成功的.但我的浏览器显示登录路径的帖子已经到了502.我不知道该怎么做.

解决方法:

我在一些帮助下解决了它.事实证明调整Nginx设置是正确的想法,但我需要调整所有这些设置,而在我尝试它们之前单独期望在我调整正确的时候收到不同的错误消息.这个错误似乎是一种全部.这是我现在使用的组合,请务必检查请求的实际标头大小,并相应地调整大小.

这是我的.ebextensions文件夹中的配置文件:

files:
  "/etc/nginx/conf.d/01_proxy.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      large_client_header_buffers 4 32k;
      fastcgi_buffers 16 32k;
      fastcgi_buffer_size 32k;
      proxy_buffer_size   128k;
      proxy_buffers   4 256k;
      proxy_busy_buffers_size   256k;

container_commands:
  01_reload_nginx:
    command: "sudo service nginx reload"

标签:nginx,ruby-on-rails,devise,elastic-beanstalk,doorkeeper
来源: https://codeday.me/bug/20190627/1307432.html