HTTP parse error, malformed request - Ruby on Rails

后端 未结 5 1737
长情又很酷
长情又很酷 2021-02-19 02:31

I see the following error in Terminal when attempting to run a Ruby on Rails app.

HTTP parse error, malformed request (): #

        
相关标签:
5条回答
  • 2021-02-19 02:38

    In my case it was silly mistake I started server on http and my url was pointing to https. I hope it would save someone's time ;)

    0 讨论(0)
  • 2021-02-19 02:50

    For those reading this in the future, consider the following:

    1. Did you change your server in your Gemfile. e.g. from Puma to Thin?
    2. Have you set up an SSL certificate?
    3. Are you starting your webserver with SSL certificate flags?
    4. Is SSL turned on in your development/production environment - and what environment are you invoking?

    If you are ok with turning off SSL in your development environment you can do so by going to:

    config/environments/development.rb and configuring:

    config.force_ssl = false

    Here is some code that works for me, using puma, that invokes SSL certification (locally). I have created my certificates and have dumped it in the relevant location:

    rails s -b 'ssl://localhost:3000?key=./.ssl/localhost.key&cert=./.ssl/localhost.crt'

    When I want to run it in a production environment from my PC I using the following:

    rails s -b 'ssl://localhost:3000?key=./.ssl/localhost.key&cert=./.ssl/localhost.crt' -e production

    HTH

    0 讨论(0)
  • 2021-02-19 02:56

    Here are some possible solutions.

    1. Make sure you are connecting through http://localhost:3000 and not https://localhost:3000.

    2. If the browser redirects to HTTPS and it's Google Chrome, try this solution that addresses an HSTS problem: https://stackoverflow.com/a/28586593

    3. Make sure you do not have the production environment (if that's what you're serving) forcing HTTPS. If that's the problem, comment this out or change true to false:

      config/environments/production.rb

      # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
      config.force_ssl = true
      
    0 讨论(0)
  • 2021-02-19 02:57

    Access the app using a different browser, or if you are in Chrome access it in Incognito mode. After this the error did not show in any browser again. Remember to remove the config.force_ssl or set it to false in the development.rb file first.

    Encountered this today after adding and then removing the config.force_ssl = true config in our Rails 6 app's development.rb file. Tried to access the app in localhost, in a Chrome browser, and the same error showed. Restared rails server several times, to no avail.

    The accessing it in different browser, where the force ssl version of the app client was never opened, worked.

    0 讨论(0)
  • 2021-02-19 03:00

    seems like you are trying to run HTTPS on your local. You need to have a TLS toolkit (like openSSL) installed on your local. OPENSSL for example.

    after you made sure of that, and if still not working, maybe you can find you're answer in the next Github issue. Seems like a bug with Puma gem. GITHUB ISSUE TALK

    0 讨论(0)
提交回复
热议问题