Helicon Ape – Helicon Tech Blog http://www.helicontech.com/articles Web Server Enhancements Fri, 12 Apr 2013 11:16:37 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.4 Debugging .htaccess with Helicon Ape http://www.helicontech.com/articles/debugging-htaccess-with-helicon-ape/ Thu, 31 Jan 2013 11:19:00 +0000 http://www.helicontech.com/articles/?p=1207 Continue reading ]]> Helicon Ape incorporates a profound tool for debugging of web-sites as well as .htaccess files, e.g. rewrite, proxy and other directives in your httpd.conf, .htaccess and .htpasswd files. The debugger will show how the server processes your requests in real time while you are navigating web site in the browser window. For each server request it presents following information:

  • request and response headers,
  • cookies,
  • server variables,
  • environment variables,
  • merged httpd.conf and .htaccess files,
  • Ape debugging log messages with maximum verbosity.

Debugger shows verbose information not only for successful requests (status code 200), but also all others: redirects 3xx, client-side errors 4xx, server errors 5xx.

This debugger allows you to connect to a remote server and read debug information live. Only your session requests will be presented in the debugger window so other user requests will not be affected. This means you can run debugging in production environment.

Launching the debugger

To run the debugger mod_developer module should be enabled. The following line in  httpd.conf should be uncommented to ensure this:

LoadModule developer_module   modules/mod_developer.so

Then:

  • run Helicon Ape Manager
  • select the site or application to debug
  • select Tools –> Start Ape Debugger
    01-start

The result will be the following:

  • a new browser window will open with the site or application selected for debugging; you’ll be able to browse the pages, perform AJAX-requests etc.
  • the Debugger tab will be opened in Ape Manager and will show the requests log.

Functionality

The Debugger tab shows the log of all your requests to the site or application being debugged. The log includes the following info about each request: the path, status code, content-type and processing time in IIS.

02

Click on the line in the log and you’ll see detailed information about the request: request and response headers, cookies, server variables, environment variables, applied httpd.conf and merged .htaccess rules, corresponding error.log and rewrite.log records (if there are any for that request).

Headers:

03

.htaccess:

04

Logs:

05

The log with all debugging info may be opened directly in browser by clicking on the link ‘Open in browser’. Clicking ‘Clear log’ will remove all log entries.

To stop debugging click ‘Stop debugging’ or in Ape Manager choose Tools –> Stop Ape Debugger.

Security

The security of the debugging process is ensured as follows.

When debugging starts the following record is put in .htaccess:

SetEnv mod_developer secure-key-XXXXXXXXXXX

where XXXXXXXXXXX is a secret randomly-generated key for access to debugging info. Upon the first request to debugging session the browser will send this key to the server and will get a cookie with this key and the id of the debugging session. All requests to the server with this cookie are logged. The same cookie is owned by web-interface of debugger  (which is shown in Debugger tab). As a result, only authorized clients (browser and debugger) are allowed to make requests to be logged and receive them.

Upon termination of debugging (click on ‘Stop debugging’) the request to the server is sent and session id and all related log records are deleted. The cookie is reset. The previous cookie left in the browser becomes invalid, the logging stops.

Remote debugging

You can start .htaccess debugging on a server remotely. To do this you need to first put the line which sets mod_developer secure key into .htaccess file on your remote web site.

SetEnv mod_developer secure-key-XXXXXXXXXXX

where XXXXXXXXXXX is any random numbers or text. Then open browser and type a link like this:

http://www.example.com/developer/_ape_start_developer_session?ape_debug=secure-key-XXXXXXXXXXX 

and use same value for XXXXXXXXXXX as you used in .htaccess file. This will start debugger window with “Waiting for data” message. This window also sets special cookie in the browser to identify your debugging session. Now open new tab in same browser and navigate to your web site. You will be reading debug information in the debug session window as you navigate through your web site live.

]]>
Search Engine Friendly (SEF) URLs for phpBB http://www.helicontech.com/articles/search-engine-friendly-sef-urls-for-phpbb/ Wed, 21 Mar 2012 14:32:53 +0000 http://www.helicontech.com/articles/?p=777 Continue reading ]]> phpBB is the most popular bulletin board engine at the moment. It offers fantastic set of features but unfortunately Search Engine Friendly (SEF or SEO) URLs is not among them. Why you may need to have SEF URLs for your phpBB forum? Because Search Engines give higher rank for pages with keywords in links. Forum is usually a great traffic generator for your web site and by using SEF URLs you can significantly increase its search engine ranking. Additionally these URLs are more pleasant for human eyes since contain readable and understandable keywords and look cleaner.

By default URLs in phpBB are not search or human friendly. So here you can find simple solution how to turn this http://www.example.com/viewtopic.php?f=46&t=212 into this http://www.example.com/Search_Engine_Friendly_URLs_212.html

Our solution is to use Helicon Ape with mod_seo module. Unfortunately Apache does not have mod_seo module, so to use this solution you will need to have phpBB running on Microsoft IIS  web server and install Helicon Ape on it. You can download latest version of Helicon Ape here.

mod_seo is a generic module that allows to modify (grep) portions of HTML output on the fly by using filters and regular expressions. Along with other features provided by Helicon Ape, like rewrite rules, conditions and database key-value maps it turns into a very powerful instrument for SEO. Various forums, blogs, shops and other services with dynamic content can be easily optimized for search engines with this module.

mod_seo can extract all links on the page, compare these links with regular expression patterns, find matching links, extract forum and post numeric IDs from these links, connect to existing forum database, get human readable and keyword reach topic names form database by IDs and then write modified links back to the HTML page before it gets to the user. Then mod_rewrite rules can be used to rewrite URLs back when user requests using these modified links. Main advantage of this technique is that it does not require any change to the forum source code. This means that you do not lose ability to upgrade your forum in future and use standard packages from the code vendor.

So what you need to do to get it working. Suppose you already have phpBB running on Microsoft IIS server. Install Helicon Ape on the server. You can find installation instructions here. By default Helicon Ape will be enabled for all sites on the server, so you may just create .htaccess file in your phpBB folder and put the following content into it:

 


# Enable mod_rewrite and mod_seo for current location
RewriteEngine On
SetEnv mod_seo

# Connect to database
DBDriver mssql
DBDParams "Data Source=(local)\SQLEXPRESS;Initial Catalog=phpbb;User ID=sa;Password=123456"

# Prepare SQL queries to find topic or forum name by ID
DBDPrepareSQL "SELECT forum_name FROM phpbb_forums WHERE forum_id=@KEY" getBBForum
DBDPrepareSQL "SELECT topic_title FROM phpbb_topics WHERE topic_id=@KEY" getBBTopic

# Declare database rewrite maps
RewriteMap BBForum dbd:getBBForum
RewriteMap BBTopic dbd:getBBTopic

# Needed to make strings URL-safe
RewriteMap slug int:slug

# SEO rules to change topic links on pages:

# viewtopic.php?f=46&t=2151&start=15 -> Topic_Title-46-215.html?start=15
SeoRule viewtopic.php\?f=(\d+)\&t=(\d+)(?:&start=(\d+))?$ \
    ${slug:${BBTopic:$2}}-$1-$2.html(?3\?start=$3) [Redirect, Scope=A]

# viewtopic.php?f=6&t=3&p=28#p28 -> Topic_Title-46-215.html?p=23#p=23
SeoRule viewtopic.php\?f=(\d+)\&t=(\d+)\&p=(\d+)$ \
    ${slug:${BBTopic:$2}}-$1-$2.html(?3\?p=$3) [Redirect, Scope=A]

# Check for possible incorrect topic name and redirect to prevent duplicate content
RewriteCond ${slug:${BBTopic:$3}}#$1 ^([^#]+)#(?!\1).+
RewriteRule ^(.+?)-(\d+)-(\d+)\.html$ %1-$2-$3.html [NC,R=301,L]

# Rewrite topic URLs back
RewriteRule ^.+-(\d+)-(\d+)\.html$ viewtopic.php\?f=$1&t=$2 [NC,QSA,L]

# SEO rules to change forum links on pages:

# viewforum.php?f=6&start=100 -> viewforum-Helicon-Zoo-6.html
SeoRule viewforum.php\?f=(\d+)(?:&start=(\d+))?$ \
    ${slug:${BBForum:$1}}-$1.html(?2\?start=$2) [Redirect, Scope=A]

# viewforum.php?f=8&sid=xxxxx -> viewforum-Helicon-Zoo-6.html?sid=xxxx
SeoRule viewforum.php\?f=(\d+)&sid=(\w+)?$ \
    ${slug:${BBForum:$1}}-$1.html?sid=$2 [Redirect, Scope=A]

# Check for possible incorrect forum name and redirect to prevent duplicate content
RewriteCond ${slug:${BBForum:$2}}#$1 ^([^#]+)#(?!\1).+
RewriteRule ^(.+?)-(\d+)\.html$ %1-$2.html [NC,R=301,L]

# Rewrite forum URLs back
RewriteRule ^.+-(\d+)\.html$ viewforum.php\?f=$1 [NC,QSA,L]

 

Don’t forget to use your database user name and password to connect. We are using SQL Server Express as a database for phpBB. For MySQL database connection string may look like this:

 

DBDriver mysql "MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
DBDParams "Data Source=server;Initial Catalog=database; User ID=database;Password=password"

 

The rules above are rather generic and you may want to change them to better meet your specific needs. Nevertheless, after putting them into the .htaccess file SEF URLs on your phpBB forum should immediately start working. New links will appear on forum pages and old links will be redirected to the new format to prevent duplicate content penalty. You can try example of mod_seo optimized phpBB on our community forum.

Hope you will enjoy this solution and wish you highest search rankings!

]]>
Сounting downloads from your site http://www.helicontech.com/articles/counting-downloads-from-your-site/ http://www.helicontech.com/articles/counting-downloads-from-your-site/#comments Mon, 21 Feb 2011 13:48:35 +0000 http://www.helicontech.com/articles/?p=456 Continue reading ]]> If you have some downloadable content on your site (installation packages), you’ll probably want to monitor the statistics of downloads. But the popular Google Analytics system cannot count that as it is working only inside html-pages. Another option is analyzing server logs, but that’s something you’ll probably choose last of all… That’s why we are offering rather a simple way of counting downloads with Helicon Ape.

The steps to be accomplished are:

  • create a table in the database to store the download counters for the products;
  • create an .htaccess in Helicon Ape which will make records into the table upon each download with the help of mod_dbd module;
  • create a simple aspx-page to show downloads statictics.

Preconditions

In the root of your site you have a downloads folder containing files for download (e.g., AudioCoder.msi, AudioDecoder.msi, AdditionalCodes.zip).
You have Helicon Ape installed on your Windows Server 2008 (IIS7).
You have SQL Server that will store the DB with downloads statistics.

Table for storing statistics

Run Microsoft SQL Server Management Studio and connect to your SQL server.

SQL Server Management Studio login window

Right click on ‘Databases’, select ‘Create Database’, enter database name (for example ‘DownloadsCounter’) and click ‘OK’.

Database creation

Now we’ll create the table itself:
Unfold the DownloadsCounter in Object Explorer, right click on ‘Tables’ and select ‘New Table…’. Name the table ‘Downloads’ and add 4 fields: id (int), moment (datetime), filename (nvarchar(50)) and ipaddress (nvarchar(50)) as shown on the pic below. You can find sql script to create table in attached DownloadsCounterExample.zip.

Table creation

Done with the table!

mod_dbd configuration

Start Helicon Ape Manager, select your site from the tree and click on ‘downloads’ folder. Now write the following config in .htaccess on the right.

Helicon Ape Manager

The config instructs mod_dbd to connect to DB, catches data from request (filename and client ip-address) and writes them into the DB.

# Helicon Ape version 3.0.0.59

# Connection settings
DBDriver mssql
DBDParams "Data Source=db2003\MSSQLSERVER2008;Initial Catalog=DownloadsCounter;\
           User ID=sa;Password=123123"

# Save Filename (for .msi & .zip files only)
SetEnvIfNoCase REQUEST_URI ^/downloads/(.+\.(?:msi|zip))$ FileNameENV=$1
SetEnvIfNoCase REMOTE_ADDR ^(.*)$ IpAddrENV=$1

# Sql query to save download event
DBDPrepareSQL "INSERT INTO DownloadsCounter.dbo.Downloads\
    (moment, filename, ipaddress)\
    VALUES (\
        GETDATE(),\
        '%{FileNameENV}e',\
        '%{IpAddrENV}e'\
    )\
" InsertDownload

# Execute sql query if request uri is .msi or .zip file
SetEnvIf request_uri \.(?:msi|zip)$ dbd_execute=InsertDownload

# limit access to statistics page to localhost only
<Files stat.aspx>
Order Deny,Allow
Deny from all
Allow from ::1 127.0.0.1 localhost
</Files>

Save your .htaccess and try to download something from the browser. If you now throw a glimpse at the ‘downloads’ table in SQL Server Management Studio, you’ll see the records appearing in it:

Table

How it works?

Helicon Ape module is processing all requests coming to /downloads/ folder. If .zip or .msi file is requested, Ape memorizes the filename (FileNameENV) and client IP (IpAddrEnv), from which the file was requested, and inserts these data into the table by means of SQL query.

Statistics viewer

The archive attached to the article includes stat.aspx which does a very simple task—shows records from ‘downloads’ table.

Of course, that’s not the sort of viewer you need, as it must be capable of showing statistics by days, months, products etc. But designing a real-life solution is beyond the scope of this article, so feel free to advance stat.aspx by yourself.

Resulting archive

Below is the archive DownloadsCounterExample.zip containing all files from this article. To do some testing just unzip it into the root of your site and replace the database password from ‘123123’ to the one you have in both .htaccess and web.config.

DownloadsCounterExample.zip

Why is this option better?

As we already noticed, Google Analytics and like services are based on JavaScript working on the page. They know nothing about static content and other files loaded from the server.

Another option (yet another extreme) is server logs. They are not always accessible, not always enabled, besides, they require writing of special parsers or analyzers. Moreover, server logs do not provide live (current moment) info. Usually log file is created daily so their analysis is only possible at the beginning of the next day.

Summing up

The method explained above is a quick and effortless way to screw downloads counter to your site using Helicon Ape mod_dbd. The example is easily expendable, e.g. you can add more fields to the table to save Referer, User-Agent, etc., or develop a customizable statistics viewer.

We’ve just given you the basement, now it’s time for you to build a house.

Best regards,
Ruslan—Helicon Tech Team

]]>
http://www.helicontech.com/articles/counting-downloads-from-your-site/feed/ 2
Make your websites work faster http://www.helicontech.com/articles/make-your-websites-work-faster/ http://www.helicontech.com/articles/make-your-websites-work-faster/#comments Thu, 27 Jan 2011 11:25:44 +0000 http://www.helicontech.com/articles/?p=375 Continue reading ]]> In April 2010 Google announced, that speed of a web site will be considered as an aspect of web search ranking. This means that web site creators and webmasters need to optimize their websites. What is the best way to do that? What if web developers are out of reach? What if changing the code is not an option? We can offer several simple and fast solutions for improving your web site performance using Helicon Ape. To start with you need to download Helicon Ape and install it on your Windows server. Native Helicon Ape Manager allows you to change your web server setting using .htaccess text files. General simple advices:

1. Cache statics

Caching static content (pictures, css files, javascript files) on the client’s side (in browser) means that having received static file once browser saves it in cache and doesn’t make a request to the server next time the html-document is requested. File will be taken from cache. Both sides win: client sends less requests, web site is working faster and server processes less requests. For instance, ordinary WordPress post page has over a dozen links to the static files (css files, pictures, scripts). Time spent on downloading these files exceeds time spent on downloading the post itself. Once having caching enabled the static content will be downloaded only once. While moving to the next page the only thing that will be downloaded is page itself. All static files will be taken from cache. In order to make browser cache static content, http-response must contain specific headers: Expires and Cache-Control. Those headers are set by mod_expires and mod_headers modules. For enabling caching, create .htacces file with the following content inside the static folder:

ExpiresActive On
Header set Cache-Control public
ExpiresByType image/.+  "access 15 days"
ExpiresByType text/css  "access 5 days"
ExpiresByType application/x-javascript "access 5 days"
ExpiresByType application/javascript "access 5 days"

In case there’s no such directory for static content and files are spread across folders of web site, than if you create following .htacces in the root of the site it will cache all static content on the web site by file extension:

<Files ~ \.(gif|png|jpg|css|js)>
ExpiresActive On
Header set Cache-Control public
ExpiresByType image/.+  "access 15 days"
ExpiresByType text/css  "access 5 days"
ExpiresByType application/x-javascript "access 5 days"
ExpiresByType application/javascript "access 5 days"
</Files>

This configuration makes server send http-responses to clients with information that pictures are to be cached for 15 days and scripts and css-files for 5 days.

2. Compress responses on the run

In order to save some time on loading the content, you can compress it. All modern browsers are able to receive comressed gzip-traffic. Text files (html-files, css-files, scripts, json-data) can be easily compressed and allow you to save 20-90% of traffic. Same time, music and video files can hardly be compressed as they have already be sized with special codecs. Here’s an example of enabling gzip-compression. Add the following line in .htaccess in the root of web site:

SetEnvIf (mime text/.*) or (mime application/x-javascript) gzip=9

As you can see, this configuration is quite simple. It’s enough to have all text documents (html, css files) and javascript-files compressed before going to the client’s side. It is worth saying, that server compresses responses only for those browsers, that support compressing. Browser informs server about its features through the headers of html-request.

3. Cache dynamic responses at server side

Often large amount of requests, addressed to database server, hinder the web site performance. For example, blog’s main page shows recent entries, recent comments, navigation menu, category list and tags. Those are several complicated requests to database. In case that information does not change often or the relevance is not vital, html-responses need to be cached without hesitation. You can choose to cache the blog’s main page once in 5-10 minutes. But that would be enough to improve main page performance in browser. Practically, application developer must decide what pages need to be cached and for how long. Also he needs to bring into life caching mechanism “out of the box” . Unfortunatelly, that doesn’t happen most of the time. Likely, mod_cache in Helicon Ape will simply and easily allow you to enable caching at server side. mod_cache supports two types of cache: disk cache and memory cache. First type saves caches data on the drive, and the second one does on memory. Memory caching is more preferable. If your server doesn’t have enough RAM, use disk cache. For example, to cache site’s homepage, we need to add the following lines in .htaccess in the root:

Header set Cache-Control public,max-age=600
SetEnvIf request_uri ^/$ cache-enable=mem

This configuration enforces caching of site’s homepage request for 10 min (600sec). Response are cached in memory. Be careful! You need to enable caching carefully. For example, pages that need authentificaton mustn’t be cached as they contain private data and need to provide different information for different users. In any cases, caching must be taking application logic into account. We’ve reviewed three simple steps for increasing the speed of your web site. Besides tangible speed-boost, which you will notice at once, the acceleration must well enhance your rating in search engine results. Website speed up graph You can see performance graph of www.helicontech.com made using Google Webmaster tools after a simple optimization. So equip your site with these tricks and enjoy dual benefit!

]]>
http://www.helicontech.com/articles/make-your-websites-work-faster/feed/ 1
IIS reverse proxy and load balancer with web admin panel http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/ http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/#comments Tue, 28 Sep 2010 15:35:59 +0000 http://www.helicontech.com/articles/?p=297 Continue reading ]]> Since build 3.0.0.50 Helicon Ape offers a web interface for the load balancer.

Web interface illustrates the current state of load balancers and their nodes.

load balancer web interface

The following info is shown for the balancer nodes:

  • Worker URL;
  • Route: name of balancer member;
  • RouteRedir: name of the node to redirect requests to in case of inaccessibility;
  • Factor: mamber relative weight;
  • Status: state of member;
  • Elected: how many times the node was chosen to process request, i.e. practically the number of processed requests;
  • Transmitted: number of bytes sent to the node;
  • Received: number of bytes received from the node;
  • EMA ResponseTime: exponential moving average of response time
  • Status TTL: period of time for which the node is excluded from the balancing process due to inaccessibility.

Here’s how you can set this handler to enjoy all this stuff:

<Location /balancer-manager/>
  SetHandler balancer-manager
  Order allow,deny
  Allow from 127.0.0.7 ::1 localhost
</Location>

Please pay attention that the URL to which the handler is mapped must be secured from unauthorized access. For instance, the access must be granted for local machine only (see example above) or basic/digest authorization must be enabled.

Feel free to try our web interface for the load balancer to facilitate control and get comprehensible statistics for any node and any balancer.

Best wishes,
Ruslan – Helicon Tech Team

]]>
http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/feed/ 1
Load balancing with Helicon Ape mod_proxy http://www.helicontech.com/articles/load-balancing-with-helicon-ape-mod_proxy/ Mon, 27 Sep 2010 10:27:28 +0000 http://www.helicontech.com/articles/?p=262 Continue reading ]]> Helicon Ape mod_proxy module provides simple way to configure load balancer. This article is giving explicit instructions of how to configure and test such load balancer.

Goal

Create simple cluster in which one front-end server (www.site.com), accessible via Internet, proxies some application operation in an intranet (not accessible via Internet).

load balancer with Helicon Ape mod_proxy

To improve stability (resistance to failures) and speed the application will run on internal servers (app1.site.com & app2.site.com) which will distribute requests between themselves. In case one server is down (scheduled maintenance, upgrade, breakdown), all requests will be directed to another server.

Requests between the servers are distributed based on the response time value. I.e. the quicker back-end returns responses (better copes with the load), the more requests it will get.

The application uses sessions, so if the request contains the cookie with session id, this request must be assigned to the back-end which initiated this session. The cookie is of the following format [session_data]![backend_id].

Static content is also shared between two internal servers (static1.site.com & static2.site.com) so they need to distribute it among themselves as well.

Configuration

Here’s the sample configuration of the balancer described above:

<VirtualHost www.site.com>

# route all requests starts with /static/ to static balancer
ProxyPass /static/ balancer://static-balancer/
<Proxy balancer://static-balancer/>
  # describe static balancer members
  BalancerMember http://static1.site.com/media/
  BalancerMember http://static2.site.com/media/
</Proxy>
# enable reversing of response redirects
ProxyPassReverse /static/ http://static1.site.com/media/
ProxyPassReverse /static/ http://static2.site.com/media/

# route all other requests to application balancer
ProxyPass / balancer://app-balancer/ stickysession=sessionid routeregex=!(.*)$
<Proxy balancer://app-balancer/>
  # describe application balancer members
  BalancerMember http://app1.site.com/ route=app1
  BalancerMember http://app2.site.com/ route=app2
</Proxy>
# enable reversing of response redirects
ProxyPassReverse / http://app1.site.com/
ProxyPassReverse / http://app1.site.com/
# enable reversing of domain in Set-Cookie headers
ProxyPassReverseCookieDomain app1.site.com www.site.com
ProxyPassReverseCookieDomain app2.site.com www.site.com

</VirtualHost>

What was that?

And here’s the explanation of the code above.

<VirtualHost www.site.com> ... </VirtualHost>

section conditions that all directives inside it are applied only to the requests to www.site.com. This is especially important when the server manges several sites.

ProxyPass /static/ balancer://static-balancer/

directive tells mod_proxy that all requests beginning with /static/ must be proxied via static-balancer balancer.

<Proxy balancer://static-balancer/> ... </Proxy>

section stores directives for static-balancer, members of this balancer in particular.

BalancerMember http://static1.site.com/media/

directives define balancer members: their working URL and load factor.

ProxyPassReverse /static/ http://static1.site.com/media/

directives are needed to reverse proxy the redirects coming from the back-ends. All redirects with URLs like http://static1.site.com/media/[path] will be substituted with http://www.site.com/static/[path].

These were the rules for static content balancer. Now let’s look at the balancer for the application itself.

ProxyPass / balancer://app-balancer/ stickysession=sessionid routeregex=^(.*)$

directive tells mod_proxy that all other requests must be proxied through app-balancer balancer. As the rule for /static/ folder is above, it will be applied earlier.

The balancing must be relative to back-end response time (default lbmethod=byresponsetime), i.e. the back-end with faster response time will get more requests with probability reverse-proportional to the response time. Response time for each back-end is averaged according to exponential moving average algorythm.

stickysession=sessionid parameter defines the name of the cookie storing the session id, and routeregex=!(.*)$ defines the regular expression to match the request route in the cookie value. In our case it’s everything after the exclamation mark (‘!’).

BalancerMember http://app1.site.com/ route=app1

directives define app-balancer members. route=app1 assignes the name to this node (route) which will be used to direct requests with corresponding sticky session.

ProxyPassReverse and ProxyPassReverseCookieDomain directives serve to reverse proxy redirects (Location header) and domains in cookies (Set-Cookie header).

Other types of load balancers

The method of load balancing is defined by lbmethod parameter of ProxyPass directive and may be one of the following:

  • byrequests to perform weighted request counting;
  • bytraffic to perform weighted traffic byte count balancing;
  • random to perform weighted random balancing;
  • byresponsetime to perform weighted response time balancing.

Nodes accessibility

The node is considered inaccessible if the balancer cannot connect to it. In such case the balancer marks it as IN_ERROR and excludes from the balancing process. In our situation it means that if app1.site.com is not accessible (e.g. due to upgrade), then the balancer will route all requests to app2.site.com. statusttl parameter of BalancerMember directive defines the period of time in seconds after which it’ll retry to establish connection to this node. The default is 300 secs.

You can learn more about mod_proxy directives and features from mod_proxy manual.

Best wishes,
Helicon Tech Team

]]>
Trace HTTP traffic and IIS configuration http://www.helicontech.com/articles/mod_developer-in-action/ Tue, 10 Aug 2010 13:00:55 +0000 http://www.helicontech.com/articles/?p=217 Continue reading ]]> Since build 3.0.0.43 Helicon Ape is equipped with brand new mod_developer module.

Revised mod_developer is capable of dispaying standard server-side debugging info:

  • headers
  • cookies
  • server variables
  • request processing duration

as well as Ape-specific details:

  • environment variables
  • merged server configuration (httpd.conf)
  • merged local configuration (.hatccess)
  • server and rewrite logs

With new mod_developer debugging of mod_rewrite rules is faster and easier as now you can see the hierarchy of subrequests invoked by RewriteRule.

To show you mod_developer in action we’ve created a special demo site. It’s a WordPress blog working with Ape and having mod_developer enabled for all visitors.

To touch live mod_developer follow the link: http://moddeveloper.helicontech.com/?ape_debug=secure-key-1231234

Note! Debugging security is ensured by mod_developer environment variable. This variable stores unique secure key which only you should know. To start debugging simply request http://yoursite.com/path/to/debug/?ape_debug=secure-key-XXXXXXX.
Debuggung may also be enabled form Ape Manager (Options → Start Ape Debugger). In this case secure key is generated automatically and is pasted into your current configuration.

Please feel free to test our mod_developer and post your impressions in comments.

Best wishes,
Helicon Tech Team

]]>
Keyword reach URLs in 5 minutes http://www.helicontech.com/articles/mod_seo/ http://www.helicontech.com/articles/mod_seo/#comments Tue, 06 Jul 2010 13:52:00 +0000 http://localhost:85/blog/?p=73 Continue reading ]]> This article is an introduction as well as a detailed guide to new mod_seo module being an integral part of Helicon Ape 3 which is destined to build good-looking URLs based on the application’s DB data or maps without necessity to change anything in its code.

Search Engine Optimization usually means a set of measures to improve web site performance for search engines, and one popular instrument for large electronic sites like forums, blogs, e-shops is Search Engine Friendly (SEF) URLs or Keyword Reach URLs. Such URL usually implies that you will see something like http://www.mysite.com/my_cool_product_name.html in the address bar instead of http://www.mysite.com/products.asp?pid=5568290. Search engines use such keywords in links to better rank pages with these keywords for search requests. Nowadays many web applications support Keyword Reach URLs either internally or by means of mod_rewrite but anyway application level support is required. Many other applications like, for example, version of WebWiz forum we are using on our web site, do not support keywords in links, so we have invented mod_seo to fill in this gap.

The idea is quite easy. Web applications like forums or blogs usually use database to store topics, posts and articles, identify posts by some IDs and use these IDs in links. This database already exists and we can easily connect to it and bind these IDs to the topic titles, where all these valuable keywords are stored.

mod_seo introduces only one directive – SeoRule – with the syntax very close to that of RewriteRule directive in mod_rewrite, but SeoRule rewrites links on pages instead of rewriting requested URLs. Together with RewriteRule and RewriteMap directives and database support (already built into Helicon Ape engine) we can make a configuration to retract keywords from database, put these keywords in the links on pages and then navigate user around the site without changing a single line of code in the web application (forum in our case).

Now we will show you how to turn this http://www.helicontech.com/forum/forum_posts.asp?TID=15116 into this http://www.helicontech.com/forum/15116-RewriteMap_and_RewriteRule_and_querystring.html step by step using our live forum as example.

What we do:

  1. Make sure mod_rewrite, mod_dbd and mod_seo modules are enabled in httpd.conf
    Enabling Helicon Ape modules
  2. Put the following lines into .htaccess in the root of our site:
    DBDriver mssql
    # include DBDParams
    DBDParams "Data Source=(local)\SQLEXPRESS;Initial Catalog=WebWizForum;User ID=sa;Password=*****"
    DBDPrepareSQL "SELECT [Subject]     FROM [WebWizForum].[dbo].[tblTopic]  WHERE [Topic_ID] =@KEY" \
                  getSeoTopic
    DBDPrepareSQL "SELECT [Forum_name]  FROM [WebWizForum].[dbo].[tblForum]  WHERE [Forum_ID] =@KEY" \
                  getSeoForum
    
    RewriteMap SeoTopic dbd:getSeoTopic
    RewriteMap SeoForum dbd:getSeoForum
    RewriteMap slug int:slug
    
    #SEO-ing
    SeoRule forum_topics\.asp\?FID=(\d+)\&title=([^\s"'$&]*) \
            forum$1-$2.html [Redirect,Scope=A]
    SeoRule forum_topics.asp\?FID=(\d+)&PN=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}-$2.html [Redirect,Scope=A]
    SeoRule forum_topics.asp\?FID=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}.html [Redirect,Scope=A]
    
    SeoRule forum_posts.asp\?TID=(\d+)\&title=([^\s"'$&]*)(?:&(get=last#\d+))? \
            $1-$2.html?4\?$4 [Redirect,Scope=A]
    SeoRule forum_posts.asp\?TID=(\d+)(?:\&PN=(\d+)\&TPN=(\d+))?(?:&(get=last#\d+))?$ \
            $1-${slug:${SeoTopic:$1|not-found}}(?2-$3).html?4\?$4 [Redirect,Scope=A]
    
    #rewrite to the original ones
    RewriteRule forum(\d+)-.*(?:-(\d+))\.html$ /forum/forum_topics.asp\?FID=$1&PN=$2 [NC,QSA,L]
    RewriteRule forum(\d+)-.*\.html$ /forum/forum_topics.asp\?FID=$1 [NC,QSA,L]
    
    RewriteRule (\d+)-.*(?:-(\d+))\.html$ /forum/forum_posts.asp\?TID=$1&TPN=$2 [NC,QSA]
    RewriteRule (\d+)-.*\.html$ /forum/forum_posts.asp\?TID=$1 [NC,QSA]

Now with explanations:

First we need to declare database maps (RewriteMap with database connection) to use in link replacing rule.

  • Declare Microsoft SQL Server driver:
    DBDriver mssql
  • And include DBDParams string for correct SQL connection
    DBDParams "Data Source=(local)\SQLEXPRESS;Initial Catalog=WebWizForum;User ID=sa;Password=*****"
  • Prepare SQL queries to select proper fields (topic/forum name) from corresponding tables of the forum database. I was using Microsoft SQL Server Management Studio to do this. Though any database management tool will do. A ‘@KEY’ in the query has a special meaning and will be substituted by the key value when map call is executed. Declaration is needed to assign names for the queries to refer to them in RewriteMap declaration. We have choosen getSeoTopic and getSeoForum as names for them.
    DBDPrepareSQL "SELECT [Subject]     FROM [WebWizForum].[dbo].[tblTopic]  WHERE [Topic_ID] =@KEY" \
                  getSeoTopic
    DBDPrepareSQL "SELECT [Forum_name]  FROM [WebWizForum].[dbo].[tblForum]  WHERE [Forum_ID] =@KEY" \
                  getSeoForum

    Topics table and corresponding SELECT query
    Topics table and corresponding SELECT query

    Forums table and corresponding SELECT query
    Forums table and corresponding SELECT query

  • Now declare database-driven maps using previously declared queries. These maps will be referred to in subsequent SeoRule directives by their names – SeoTopic and SeoForum.
    RewriteMap SeoTopic dbd:getSeoTopic
    RewriteMap SeoForum dbd:getSeoForum
  • Define slug map that is used to remove special characters from topic names to make our links more friendly for browsers and user eyes.
    RewriteMap slug int:slug
  • Now it is time for SeoRule directives.
    New URL format for main forum pages includes the forum number FID and the forum name taken from the database: http://www.helicontech.com/forum/forum11-Helicon_Ape.html
    [Redirect] flag forces requests to old-style links to be redirected to new analogues (for the above link it’s http://www.helicontech.com/forum/forum_topics.asp?FID=11)
    [Scope=A] says mod_seo to search and replace URLs in tags only
    SeoRule forum_topics.asp\?FID=(\d+)&PN=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}-$2.html   [Redirect,Scope=A]
    SeoRule forum_topics.asp\?FID=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}.html   [Redirect,Scope=A]
  • New URL format for topic pages includes the topic number TID (as the topic name is not unique) and the topic name taken from the db: http://www.helicontech.com/forum/10000-ISAPI_and_ZEND_Framework.html
    [Redirect] flag will deal with its ancestor: http://www.helicontech.com/forum/forum_posts.asp?TID=10000)
    SeoRule forum_posts.asp\?TID=(\d+)(?:\&PN=(\d+)\&TPN=(\d+))?(?:&(get=last#\d+))?$ \
            $1-${slug:${SeoTopic:$1|not-found}}(?2-$3).html?4\?$4   [Redirect,Scope=A]
  • As the forum engine doesn’t understand the new URL format, we use rewriting to convert it to habitual one, e.g. http://www.helicontech.com/forum/forum_posts.asp?TID=10000 for forum topics
    RewriteRule ^forum/forum(\d+)-.*(?:-(\d+))\.html$ /forum/forum_topics.asp\?FID=$1&PN=$2 [NC,QSA,L]
    RewriteRule ^forum/forum(\d+)-.*\.html$ /forum/forum_topics.asp\?FID=$1 [NC,QSA,L]

    and for forum posts

    RewriteRule ^forum/(\d+)-.*(?:-(\d+))\.html$ /forum/forum_posts.asp\?TID=$1&TPN=$2 [NC,QSA]
    RewriteRule ^forum/(\d+)-.*\.html$ /forum/forum_posts.asp\?TID=$1 [NC,QSA]
  • The result is a page like this:
    Forum with mod_seo enabled

The pleasant thing is you don’t need to change anything in your application — mod_seo and mod_rewrite take care of all cycle of transformations and you just enjoy the SEF picture.

Same technique can be used for many other database driven applications like forums, blogs or e-shops. Existing database may be used to transform links or new maps can be created.

If you need assistance with doing same thing for your application, you can get a Premium Support Plan from us and our support team will be happy to tailor a custom solution for you!

Best regards,
Yaroslav, Anton — HeliconTech Team

]]>
http://www.helicontech.com/articles/mod_seo/feed/ 9
Automatic cache cleaning in Helicon Ape http://www.helicontech.com/articles/automatic-cache-cleaning/ http://www.helicontech.com/articles/automatic-cache-cleaning/#comments Wed, 12 May 2010 10:30:00 +0000 http://localhost:85/blog/?p=72 Continue reading ]]> Up to version 3.0.0.39 Helicon Ape cache could be cleaned only manually. Memory-based cache (mod_mem_cache) required recycling of corresponding application and disk-based cache (mod_disk_cache) cleaning implied manual files deletion form the file system. That was slightly inconvenient, to put it mildly.

Helicon Ape 3.0.0.39 (and newer) got support of cache cleaning upon request.
Now, to clean cache just set the cache-clear environment variable. This will cause cache cleaning corresponding to the current request (context).

Setting cache-clear variable using SetEnvIf directive provides flexibility of conditions that will lead to cache cleaning.

For example, to trigger cache cleaning by requesting specific URL:

SetEnvIf request_uri ^/system/cache/clear/$ cache-clear=1

To trigger cache cleaning by appending specific query string value:

SetEnvIf Query_String clear_cache_request cache-clear=1

For security purposes it may be necessary to clean cache only from definite IP address:

SetEnvIf (Query_String clear_cache_request) and (Remote_Addr 11\.22\.33\.44) cache-clear=1

Cache cleaning may take some time, so be ready.

When cache cleaning is over, the error.log (with info or higher verbosity level) will display the number of deleted records.

Best regards,
Ruslan, Anton – Helicon Tech Team

]]>
http://www.helicontech.com/articles/automatic-cache-cleaning/feed/ 3
Titbits: Making Ape work with Plesk 9.5.1 http://www.helicontech.com/articles/making-ape-work-with-plesk/ http://www.helicontech.com/articles/making-ape-work-with-plesk/#comments Thu, 22 Apr 2010 07:39:00 +0000 http://localhost:85/blog/?p=71 Continue reading ]]> If you have Ape and Plesk installed on your server, you may come across the issue that Ape is not working in it’s entirity. This may be caused by the fact that Plesk overrides the handlers list for each domain it creates. Like this:

<location path="Example.com">
        <system.webServer>
            <handlers accessPolicy="Read, Script">
                <clear />
                <add name="Plesk_Handler_05171048" path="*.dll" verb="*"
                    modules="IsapiModule" resourceType="File"
                    requireAccess="Execute" allowPathInfo="true" />
                <add name="Plesk_Handler_05171080" path="*.exe" verb="*"
                    modules="CgiModule" resourceType="File"
                    requireAccess="Execute" allowPathInfo="true" />
                <add name="StaticFile" path="*" verb="*"
                    modules="StaticFileModule,DefaultDocumentModule,
                    DirectoryListingModule" resourceType="Either" />
            </handlers>
            ...
    </location>

To add handler for Helicon Ape, you need to add this simple spell to the root web.config for the site:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>

    <handlers>
      <add name="Helicon.Ape Handler" path="*.apehandler" verb="*"
          type="Helicon.Ape.Handler" resourceType="Unspecified"
          preCondition="integratedMode" />
    </handlers>

  </system.webServer>
</configuration>

Guess, this small hint will make Plesk and Ape cohabitation on your server more peaceful.

Best regards,
Sergey, Anton – Helicon Tech Team

]]>
http://www.helicontech.com/articles/making-ape-work-with-plesk/feed/ 482