Slow response testing localhost sites in Google Chrome on Mac OS X

Last week I noticed the response of localhost requests were slow in Google Chrome, but responded very quickly in Safari. I suspected Chrome was submitting my local requests to it’s data hunger servers to build an even better profile of me.
I tweaked a lot of Chrome settings so everything would be kept private, but no success. After several attempts I found the problem:

To test multiple sites and testing multi-domain rails applications I’ve changed my /etc/hosts file to contain the following items.

127.0.0.1 nice-domain.local
127.0.0.1 nice.sub-domain.local
127.0.0.1 gamecreatures.local

So calling: “gamecreatures.local” in Chrome causes a too long delay for showing something..
calling “gamecreatures.local” in Safari responded instantly..

After doing some research, I’ve learned Apple is doing something special with the .local postfix. It is used by the Bonjour services somehow. I don’t know exactly what, but they do…

So changing all the extension from “.local” to something else for example “.loc” solved the issue for me:

127.0.0.1 nice-domain.loc
127.0.0.1 nice.sub-domain.loc
127.0.0.1 gamecreatures.loc

Now Chrome also responds instantly…
Sorry Google for “assuming” you trying to steal all data from me… (Or should I use the _nomap extension for this one too ?!?)

Ruby on Rails / ChiliProject encoding issues

This week I’ve decided to exchange Redmine for the ChiliProject. The reason for this is the support for Ruby 1.9. My Apache Passenger server runs Ruby 1.9 so for Redmine I needed a seperate webserver.

When I tried to access the “My Account” page I recieved the following error:

ArgumentError (invalid byte sequence in US-ASCII):
  <internal:prelude>:10:in `synchronize'
  passenger (3.0.7) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.7) ...
`handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.7) helper-scripts/passenger-spawn-server:99:in `<main>'

Rendering /data/www/rails/chili/public/500.html (500 Internal Server Error)

Solution

How should I solve this? The chiliproject has an issue related to this: https://www.chiliproject.org/issues/591.

The following Apache configuration fixed the issue: (The sample is on a FreeBSD system)

I added the following code to a file in the /usr/local/apache22/envvars.d/environment.env

export LC_CTYPE="en_US.UTF-8"

Problems I ruled out or fixed

While trying I also made sure the following things were configured:

I made sure the database is UTF-8. I re-created the database
an ran the migrations again.

create database chiliproject character set utf8;

I used the mysql2 connector instead of the mysql connector in database.yml

PHP’s Frustrating Flush

PHP not listening when you try to flush data. Try the following, it helped for me:


@ob_flush(); // try a normal flush
flush();

If PHP isn’t flushing it could be your webserver that’s collecting your output for gzipping:


mod_gzip_on no

This worked for me..

Apache Authentication and Mongrel Cluster

Currently I’m running a mongrel cluster for my rails application. This works much nicer then the FastCGI version.
There was only one problem, I had an .htaccess file to restrict access to the public directory.


AuthName "Somewhere"
AuthType Basic
AuthUserFile /home/nobody/.htpasswd
Require valid-user

The problem was I needed to enter this login data 2 times.
Well after doing some google research I found out the problem was the location of the authorizationcode. I think the .htaccess file is used by every Process of the ProxyBalancer… But I’m not sure…

The solution for this problem was to place the authorization code in the proxy balancer:



BalancerMember http://rails_site:5532
BalancerMember http://rails_site:5533
AuthName "Somewhere"
AuthType Basic
AuthUserFile /home/nobody/.htpasswd
Require valid-user

That’s all ;-)