# Ssl\_requirement: transitions from https to http and vice versa are slooooow

**URL:** <https://www.ruby-forum.com/t/ssl-requirement-transitions-from-https-to-http-and-vice-versa-are-slooooow/130700>\
**Category:** Rails\
**Created:** [March 2, 2008, 4:55am UTC](https://www.ruby-forum.com/t/ssl-requirement-transitions-from-https-to-http-and-vice-versa-are-slooooow/130700 "2008-03-02T04:55:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 2, 2008, 4:55am UTC](https://www.ruby-forum.com/t/ssl-requirement-transitions-from-https-to-http-and-vice-versa-are-slooooow/130700/1 "2008-03-02T04:55:06Z")

</div>

Hi,

I’m using rails 1.2.5 along with nginx and mongrel\_cluster to serve  
both encrypted and unencrypted content.

I installed the ssl\_requirement plugin to force https on certain pages/  
actions.

ssl\_requirement works, but whenever I go from an unencrypted page on  
my site to an encrypted page (or vice versa) the time to render the  
page is HUUUGE (around 1 minute for some simple html that should  
normally take about 1 second to render).

e.g., if I am viewing this page: [https://blahblah.com/stuff](https://blahblah.com/stuff) and I  
click on a link within that page that links to  
[http://blahblah.com/otherstuff](http://blahblah.com/otherstuff),  
my browser will churn for about 1 minute before rendering the new  
page.

some interesting points.

1. this does not happen when going from https to https, nor does it  
take place when going from http to http.

2. if I click on the hyperlink a _second_ time while I’m waiting for  
the new page to render, it renders almost immediately (i.e. I can  
“coax” the new page into loading by clicking on it twice).

Any ideas as to what’s causing this lag?

my nginx config file is shown below along with the top/relevant  
portion of my controller that uses ssl\_requirement

############begin top of controller #########  
class AccountController \< ApplicationController  
layout “account”  
before\_filter :login\_from\_cookie  
ssl\_required :signup, :login  
##########end top of controller ##############

##########begin nginx virtual host config file ##############

# Nginx virtual host configuration file

# to be included by nginx.conf

# Load balance to mongrels

upstream mongrel\_cluster {  
server 0.0.0.0:8000;  
server 0.0.0.0:8001;  
server 0.0.0.0:8002;  
}

# Begin virtual host configuration

server {

# Familiar HTTP settings

listen 80;  
server\_name [e.com](http://e.com) \*.e.com;  
root /home/e2/a2/public;  
access\_log /var/log/nginx/e.com.access.log main;  
error\_page 500 502 503 504 /500.html;  
client\_max\_body\_size 50M;

# First rewrite rule for handling maintenance page

if (-f $document\_root/system/maintenance.html) {  
rewrite ^(._)$ /system/maintenance.html last;  
break;  
}  
location / {  
index index.html index.htm;  
# Forward information about the client and host  
# Otherwise our Rails app wouldn’t have access to it  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_max\_temp\_file\_size 0;  
# Directly serve static content  
location ~ ^/(images|javascripts|stylesheets)/ {  
expires 10y;  
}  
if (-f $request\_filename) {  
break;  
}  
# Directly serve cached pages  
if (-f $request\_filename.html) {  
rewrite (._) $1.html break;  
}  
# Otherwise let Mongrel handle the request  
if (!-f $request\_filename) {  
proxy\_pass http://mongrel\_cluster;  
break;  
}  
}  
}

server {

listen 443;  
ssl on;  
#path to certificate  
ssl\_certificate /etc/ssl/certs/myssl.crt;  
#path to ssl key  
ssl\_certificate\_key /etc/ssl/myssl.key;

server\_name [e.com](http://e.com) \*.e.com;  
root /home/e2/a2/public;  
access\_log /var/log/nginx/e.com.access.log main;  
error\_page 500 502 503 504 /500.html;  
client\_max\_body\_size 50M;

# First rewrite rule for handling maintenance page

if (-f $document\_root/system/maintenance.html) {  
rewrite ^(.\*)$ /system/maintenance.html last;  
break;  
}

location / {  
index index.html index.htm;  
# Forward information about the client and host  
# Otherwise our Rails app wouldn’t have access to it  
# set X-FORWARDED\_PROTO so ssl\_requirement plugin works  
proxy\_set\_header X-FORWARDED\_PROTO https;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_max\_temp\_file\_size 0;  
# Directly serve static content  
location ~ ^/(images|javascripts|stylesheets)/ {  
expires 10y;  
}  
if (-f $request\_filename) {  
break;  
}  
# Directly serve cached pages  
if (-f $request\_filename.html) {  
rewrite (.\*) $1.html break;  
}  
# Otherwise let Mongrel handle the request  
if (!-f $request\_filename) {  
proxy\_pass http://mongrel\_cluster;  
break;  
}  
}

}
