Archive for February, 2008

10 Feb 2008

How to use the .NET URL Rewriter and Reverse Proxy to run WordPress on IIS

4 Comments Uncategorized

First off I would like to say that many of my readers are very intelligent, they picked up on a one line sentence in my last post about my new design and Coder Journal switching from Linux to Windows.

I also moved hosts from GoDaddy’s shared Linux hosting. To GoDaddy’s virtual dedicated hosting on Windows. This proved difficult since URL Rewriting isn’t currently built in to IIS 6.0 like it is in Apache. I will talk a little about this setup in a later post.

Switching from Linux to Windows wasn’t the part that really intrigued many of them, it happens every day so why would it? It was the fact that I was able to get the same level of URL Rewriting out of IIS 6.0 as I was out of Apache’s mod_rewrite and still be able to make WordPress look and function like it was running on Apache.

So to get started I just want to say, while I know there are other solutions out there to get WordPress hosted on IIS with the exact same outcome as what I am going to present below. I did this for the following reasons:

  1. I am a .NET guy and I love developing software that is popular on other platforms on .NET just to see if it can be done.
  2. I also believe in Eating One’s Own Dog Food, and the URL Rewriter and Reverse Proxy that I am presenting below, and that is used in Coder Journal, is my own creation.

What This Post Covers

This post is meant to provide an insight in to a technology, Reverse Proxy, that many developers are unaware of and it will be demonstrated through the eyes of my blog and how it works in regards to WordPress/IIS 6.0. Some of the basics will be covered such as the working of a URL Rewriter and Reverse Proxy. This post will not cover how to code a URL Rewriter or Reverse Proxy in C#. The reader should also have a basic understanding of how RegEx, HTTP, and URL Rewriters.

The Problem

On IIS 6.0, and previous versions, due to a lack of any standardized URL Rewriting process built in, so developers have to take nice visitor and SEO friendly URL’s like this:

http://www.coderjournal.com/2008/02/10/sample-post/

And make IIS 6.0 compatible ugly URL’s, which may or may not be SEO friendly, and neither URL is as visitor friendly as the one above.

http://www.coderjournal.com/?p=123
http://www.coderjournal.com/index.php/2008/02/10/sample-post/

My Solution Used On Coder Journal

The solution I choose was influenced by a number of factors, a couple that will change for the better when IIS 7.0 is released. The factors are:

  • I need to run PHP for WordPress.
  • I need to run FastCGI for IIS 6.0 to get the best performance out of PHP.
  • .NET and PHP run separate from each other, so I cannot use a .NET URL Rewriter to control which PHP file is chosen to run. (This changes in IIS 7.0 with Integrated Pipelines)
  • I need to pass all requests to www.coderjournal.com through .NET, which has a performance loss for rendering static files such as image, and text files. (This changes in IIS 7.0 with Integrated Pipelines)
  • I need to keep the URL’s friendly for visitors and SEO.

So because of what I listed above I needed to create two web servers to host www.coderjournal.com, which I will talk about later on in this article. One of the servers is the public interface to www.coderjournal.com, which I will call frontend, and the other is the Backend WordPress web server, which I will call backend that only handles standard WordPress with the ugly URL’s listed above, this one is not public. The picture will demonstrate the structure better than I can explain.

Coder Journal Web Structure

As you can see, from the above picture, all requests to WordPress are handled by the frontend server for this blog. This all happens through a technique known as Reverse Proxy.

A reverse proxy dispatches in-bound network traffic to a set of servers, presenting a single interface to the caller. For example, a reverse proxy could be used for load balancing a cluster of web servers. In contrast, a forward proxy acts as a proxy for out-bound traffic. For example, an ISP may use a proxy to forward HTTP traffic from its clients to external web servers on the internet; it may also cache the results to improve performance.

So with out going in to a deep explanation of how I was able to accomplish the reverse proxy, basically for every request that comes in to frontend server that meets a certain criteria I make another HTTP web request to the backend server and then write it’s response back to the original frontend server request.

Step 1 – Setting Up .NET to Process All Requests

Setup your frontend server to process everything through the .NET framework.

  1. Open IIS and right-click on the website and select Properties.
  2. Click the Configuration button under Application Settings section
  3. Click the Insert… button to create a new wildcard mapping
  4. Set the executable textbox to aspnet_isapi.dll file location.
    for .net 2.0, 3.0, 3.5: C:WindowsMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll
  5. Make sure the checkbox Verify that file exists is not checked.
  6. Press OK to confirm and close all the windows.

Step 2 – Install PHP/WordPress

Just follow this article on IIS.NET for installing PHP/WordPress on IIS 6.0. You may also want to install FastCGI, I recommend this, but it is optional.

Step 3 – Setting Up the URL Rewriter and Reverse Proxy Rules

The criteria for the requests are put inside the URL Rewriter Rules files. But before the proxy request is made, I must check to make sure the file being requested doesn’t already exist on the frontend server. If it does exist on the frontend server I don’t want to make a reverse proxy request. The following is the code used to do that.

# any file that exists just return it
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]

Then after I check to make sure the file doesn’t exist on the frontend server I make the request to the backend using the following rules.

# proxy all connections through to the backend server
RewriteRule ^(/[0-9]{4}/.*) http://backend/index.php$1 [P]
RewriteRule ^(/tags/.*) http://backend/index.php$1 [NC,P]
RewriteRule ^(/topics/.*) http://backend/index.php$1 [NC,P]
RewriteRule ^(/author/.*) http://backend/index.php$1 [NC,P]
RewriteRule ^(/comments/feed/.*) http://backend/index.php$1 [NC,P]
RewriteRule ^(/page/.*) http://backend/index.php$1 [NC,P]
RewriteRule ^(.*) http://backend$1 [P]

Conclusions

To get the exact same setup as I have, you will need the following software, which is all free for download:

As always if you have any questions about the setup or the performance please post them below in the comments and I will answer them and or update the post as needed.

Happy Coding.

07 Feb 2008

Allow More Than One Remote Desktop Login Connection On GoDaddy’s Virtual Dedicated Server’s

No Comments Uncategorized

Ever have one of those days where you are so eager to get home and watch Lost that you totally forget to log out of your Remote Desktop instance? Well I have, and usually it is not a big deal, because Windows Server Terminal Services allows you to have multiple logins with the same user account. Unless you are running on GoDaddy Virtual Dedicated server, where the default configuration only allows one connection.

So I called up GoDaddy and they said my only option was to power cycle the machine. Gasp… Yes you head me right, a power cycle of a live running website. My heart actually skipped a beat when this level one tech said this. I also wasn’t allowed to talk to level two techs because they can only be graced with e-mail, talking to actual GoDaddy customers is beneath them I guess.

Well to make a long story short I found a way to increase my Maximum Connections to two, which is just enough to allow me to login with the Admin account and kill my other session. Here is what you have to do:

To Set Maximum Connections for Remote Desktop Connections

  1. From your servers’s Start menu, point to Programs, point to Admin Tools, and then click Terminal Services Configuration.
  2. In the right pane of the window, click RDP-Tcp.
  3. Click the Network Adapters tab.
  4. Change the Maximum Connections to 2.

Also while you are at it you may want to change the session log out time.

To Set Timeout Options for Remote Desktop Connections

  1. From your computer’s Start menu, point to Programs, point to Admin Tools, and then click Terminal Services Configuration.
  2. In the right pane of the window, click RDP-Tcp.
  3. Click the Sessions tab.
  4. Specify the values you want to use.

I usually set End Disconnected Sessions to 10 minutes and Idle Session Limit to 30 minutes.

I don’t know why the maximum connections for RDP isn’t set to a reasonable value as the default, but many of the default settings at GoDaddy and puzzling and disturbing. So it really doesn’t surprise me.

07 Feb 2008

Add Data to Google Spreadsheets Using Forms

1 Comment Uncategorized

So today I was reading one of my favorite blogs, Google Operating System, and I saw an interesting development on the Google Docs front.

Google Spreadsheets has a new feature that lets you create a form to accept data. When you go to the Share tab, there’s a new option to “invite people to fill out a form”. The form is very simple and can be customized by changing the order of entries, their labels and the type of answers. It’s also a nice way to get feedback people who wouldn’t normally collaborate on a spreadsheet.

This is really exciting stuff, especially for many of my clients that just want a quick and dirty form to ask a couple questions of their customers. The bonus is that it comes out in the format everybody wants. Microsoft Excel! Here is what the Offical Blog Post had to say:

Responses are automatically added to your spreadsheet. You can even keep a closer eye on them by adding the Google Docs forms gadget to your iGoogle homepage, created by software engineers Valerie Blechar and Sarah Beth Eisinger (in her first month at Google!). It lists your recent active forms, with new responses highlighted. Add this gadget to your iGoogle page: Add to Google

To test this out I created my own survey for my readers to tell me how I am doing? Located at: http://spreadsheets.google.com/viewform?key=pmGAQxFEGHWGV6o0976XeJQ

I found that you can use/host the forms in the following ways:

  1. In an <iframe /> with this URL http://spreadsheets.google.com/viewform?key={your key}
  2. On your own page with a standard form POST to http://spreadsheets.google.com/formResponse?key={your key}
  3. In Emails with a standard form POST to the same URL as in number 2

So I see an immediate impact on my life in rolling out custom forms to my clients to help them gather the information that is important to them.  Also if you have the time there are some questions that are important to me.  So if you wouldn’t mind please click here or on the left in the navigation bar:  How is Coder Journal doing?