# Web Service behind https

**URL:** <https://discuss.rubyonrails.org/t/web-service-behind-https/21261>\
**Category:** rubyonrails-talk\
**Created:** [December 5, 2007, 12:33am UTC](https://discuss.rubyonrails.org/t/web-service-behind-https/21261 "2007-12-05T00:33:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul10](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Paul10](https://discuss.rubyonrails.org/u/Paul10)\
**Post date:** [December 5, 2007, 12:33am UTC](https://discuss.rubyonrails.org/t/web-service-behind-https/21261/1 "2007-12-05T00:33:56Z")

</div>

Hi,

I'm trying to create a web service that runs on https (i.e ssl). I have install the ssl\_requirement plugin and in my webservice controller I have the lines

ssl\_required :method\_name

In development I had this commented out, as I wasn't running https locally. When I called MethodName it worked fine (in development).

But in production with ssl when I call the method. It returns a 302

When I check the production logs I see the following:

Redirected to http://…myurl… Filter chain halted as [#\<ActionController::Filters::ClassMethods::SymbolFilter:0xb759fb34 @filter=:ensure\_proper\_protocol\>] returned false. Completed in 0.00029 (3506 reqs/sec) | DB: 0.00000 (0%) | 302 Found [https://…myurl…]

Am I doing somethign horribly wrong? Any suggestions?

Just in case it helps I am also using ssl\_required in some other controllers and it's working as I'd expect there.

Thanks (in advance) for any help

Regards,

Paul

---

<div class="post-metadata">

**Author:** ![Mike\_Subelsky1](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mike\_Subelsky1](https://discuss.rubyonrails.org/u/Mike_Subelsky1)\
**Post date:** [December 5, 2007, 1:54pm UTC](https://discuss.rubyonrails.org/t/web-service-behind-https/21261/2 "2007-12-05T13:54:50Z")

</div>

Paul,

We'd need to know more about your production environment to help further, but a very common problem is between the https server and your application. The https server usually needs to include some kind of header so Rails knows that it's talking https. If you're using Apache to talk to a Mongrel server (for example), you need to include the X\_FORWARDED\_PROTO header in the virtual host directive for your production server (and make sure your SSLEngine is turned on).

Below is a snippet of configuration I use on my development machine. In production you probably wouldn't want to use ProxyPass -- it would be better to use something like mod\_balance against a cluster of Mongrels.

\<VirtualHost \*:443\> SSLEngine On ServerName localhost ServerAlias 127.0.0.1

ProxyPass / [http://localhost:3000/](http://localhost:3000/) ProxyPassReverse / [http://localhost:3000](http://localhost:3000) ProxyPreserveHost on RequestHeader set X\_FORWARDED\_PROTO 'https' \</VirtualHost\>

By the way, it's pretty easy to set up your own https server in development, which is better than commenting things out. I wrote up a quick article about it here:

[http://www.subelsky.com/2007/11/testing-rails-ssl-requirements-on-your.html](http://www.subelsky.com/2007/11/testing-rails-ssl-requirements-on-your.html)

Also helpful were these articles, which have lots of good information even if you're not using Mongrel:

[http://blog.innerewut.de/2006/06/21/mongrel-and-rails-behind-apache-2-2-and-ssl](http://blog.innerewut.de/2006/06/21/mongrel-and-rails-behind-apache-2-2-and-ssl)[http://mongrel.rubyforge.org/docs/apache.html](http://mongrel.rubyforge.org/docs/apache.html)

-Mike Subelsky subelsky.com
