12

I'm using the Thin web server to serve my Rails app.

  • Starting the server with thin start serves http requests.
  • Starting the server with thin start --ssl serves https requests.

Is there a way to have thin serve both http and https requests concurrently?

The reason I ask is because when I use redirect_to some_path in my controllers, they redirect to http. Since thin is serving https requests, nothing is rendered.

Note: I'm using Rack::SSL in Rails 3.0.7.

Graham Swan
  • 4,818
  • 2
  • 30
  • 39
  • Simplest option is probably to run two separate instances of thin: one accepting SSL requests and one accepting plaintext requests. Any reason you don't want to do this? (Alternatively, if thin is running behind another web server, like Apache or Nginx, you only need one instance of thin: the frontend server can report whether the request came in over SSL.) – Jeremy Roman Mar 04 '12 at 23:36
  • You can't run two instances of `thin` on the same port. – Graham Swan Mar 04 '12 at 23:39
  • 3
    You can't accept both HTTP and HTTPS connections on the same port, either. (This is why, by default convention, HTTP runs on port 80 whereas HTTPS runs on port 443.) – Jeremy Roman Mar 04 '12 at 23:40
  • Ah, you're right! I was confused because ports 80 and 443 are hidden since they're the default. Perhaps I need to figure out how to force `redirect_to` to push users to `https` instead. If you want to convert your comment above into an answer, I'll accept it. – Graham Swan Mar 04 '12 at 23:48
  • 2
    I have HTTP running on port 3000 and HTTPS running on port 3001. How would you create a "smart redirect" policy for your development environment such that redirects from HTTP to HTTPS also changes the port from 3000 to 3001? Thanks :) – jamesfzhang Oct 02 '13 at 17:18

2 Answers2

8

(Comment converted to answer as requested.)

Simplest option is probably to run two separate instances of thin: one accepting SSL requests and one accepting plaintext requests. Any reason you don't want to do this? (Alternatively, if thin is running behind another web server, like Apache or Nginx, you only need one instance of thin: the frontend server can report whether the request came in over SSL.)

You can't accept both HTTP and HTTPS connections on the same port. (This is why, by default convention, HTTP runs on port 80 whereas HTTPS runs on port 443.)

Jeremy Roman
  • 16,137
  • 1
  • 43
  • 44
4

you can use foreman (https://github.com/ddollar/foreman);

You create a Procfile with 2 process then start both with forman start command.

put this on a file called Procfile:

web: thin start
ssl: thin start --ssl

Then use foreman start and he start the 2 process. This is how i am using... hope this helps you!

  • 2
    How does this work since you cannot have 2 instances of thin running on the same port? And even if you start the ssl instance on another port, say `thin start --ssl -p 3001`, how do you intelligently handle redirects from http to https within your application? – jamesfzhang Oct 02 '13 at 17:16
  • 1
    @JZ11 Nginx will intelligently handle redirects/forwards depending on protocol. But I'd also like to know the workaround. – Damien Roche Oct 10 '13 at 04:44