Configuring NGinx as a Reverse Proxy for RETS Server

Ever heard of NGinx? If not, Let me tell you it is well known for its performance, caching and small signatures. Many companies are using it as Reverse Proxy Server and Cache Server to speed up the user’s browsing experience. Parallel is one of them. Their latest release for Linux (which is Plesk 11) include it as a builtin component, when enabled, It uses NGinx HttpProxyModule as Reverse Proxy Server in front of apache Apache.

Here, I will make use of Plesk 11’s NGinx to proxy a RETS (Real Estate Transaction Standard) server.

  1. Create a file “rets.conf” at “/etc/nginx/conf” having following contents

    server {

    listen YOUR_SERVER_IP:80;

    server_name rets.example.com;

    client_header_timeout 3m;

    client_body_timeout 3m;

    send_timeout 3m;

    location / {

    proxy_set_header Host $host;

    proxy_pass http://rets.rets-server.net:6103/;

    proxy_read_timeout 100m;

    proxy_connect_timeout 100s;

    proxy_send_timeout 100m;

    proxy_buffering off;

    }

When you browse http://rets.example.com you should see same response as of http://rets.rets-server.net:6103 . Many RETS server also requires HTTP Authentication. If yours does not, you are good to go. Otherwise, You are going to get “401 Athuntication Failed” error code for your login request. WHY? Because, NGinx filters out all the HTTP Authentication headers. No where I could find to let the NGinx forward them as it is. Anyway, One of the alternative methods is to use the NGinx HttpHeadersModule. Here is how to do it.

  1. You need to add a HTTP custom header while sending login request and put base64 encoded username and password.

    “My-Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=”

    “dXNlcm5hbWU6cGFzc3dvcmQ=” is base64 encoding of “username:password”

    Here how you will do it using PHRETS

     $phrets->AddHeader(‘My-Authorization’,’Basic ‘.base64_encode(“{$rets->username}:{$rets->password}”));

    Or alternatively, If you are calling through PHP CURL.

     curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(‘My-Authorization: Basic ‘ . base64_encode(“{$rets->username}:{$rets->password}”)));

 

  1. Now, you need to pass newly added “My-Authorization” header to RETS Server.

    server {

    listen YOUR_SERVER_IP:80;

    server_name rets.example.com;

    client_header_timeout 3m;

    client_body_timeout 3m;

    send_timeout 3m;

    location / {

    proxy_set_header Authorization $http_my_authorization;

    proxy_pass http://rets.rets-server.net:6103/;

    proxy_read_timeout 100m;

    proxy_connect_timeout 100s;

    proxy_send_timeout 100m;

    proxy_buffering off;

    }

 

That’s it, Now, reverse proxy will work like charm.