Wednesday, February 25, 2009

Tool for encoding XML/HTML tags

Here is a website that will convert all of your XML or HTML tags for display in a blogger post. Basically, it changes < to &lt; and > to &gt;. I'm sure it does a lot more than that too, but that is the most important things it does.

http://www.centricle.com/tools/html-entities/

Configuring virtual hosts in Jetty

I just figured out how to do virtual hosting in Jetty. I have a customer with two sites. The first site (I will call it webappsite.com) is running a java webapp on the root of the site and has a ROOT.war in the webapps directory. The second site (calling it staticsite.com) is currently just a static site. I wanted the site content for the static site to be easily accessible, so I put it into the user's home directory. Both sites need to run on the same IP number and port number, so it was necessary to use Jetty's virtual hosting features.

The webapp on webappsite.com is automatically deployed from the ROOT.war file. I didn't need to do anything extra in any configuration files for it to work. However, since I wanted a static file area on that site as well, I went ahead and added a configuration file to set that up. This wasn't necessary to make this site work and was only done to be able to serve static files stored outside of the ROOT.war file.

I also added a configuration file for staticsite.com. This was necessary for this site to work. Both of these configuration files were put into Jetty's contexts directory. The file for webappsite.com is called contexts/webappsite.xml (sorry for the horrid layout -- I need to figure out how to better post xml code in blogger):

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<configure class="org.mortbay.jetty.handler.ContextHandler">
<call class="org.mortbay.log.Log" name="debug"><arg>Configure webappsite.com site</arg></call>
<set name="contextPath">/web</set>
<set name="resourceBase"><systemproperty name="user.home" default=".">/sites/webappsite.com/web/</systemproperty>
<set name="handler">
<new class="org.mortbay.jetty.handler.ResourceHandler">
<set name="welcomeFiles">
<array type="String">
<item>index.html</item>
</array>
</set>
<set name="cacheControl">max-age=3600,public</set>
</new>
</set>
<set name="VirtualHosts">
<array type="java.lang.String">
<item>192.168.0.1</item>
<item>webappsite.com</item>
<item>www.webappsite.com</item>
<item>alternatedomainforsite.com</item>
<item>www.alternatedomainforsite.com</item>
</array>
</set>
</set>
</configure>
The static site's config file is called contexts/staticsite.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<configure class="org.mortbay.jetty.handler.ContextHandler">
<call class="org.mortbay.log.Log" name="debug"><arg>Configure staticsite.com site</arg></call>
<set name="contextPath">/</set>
<set name="resourceBase"><systemproperty name="user.home" default=".">/sites/staticsite.com/</systemproperty>
<set name="handler">
<new class="org.mortbay.jetty.handler.ResourceHandler">
<set name="welcomeFiles">
<array type="String">
<item>index.htm</item>
</array>
</set>
<set name="cacheControl">max-age=3600,public</set>
</new>
</set>
<set name="VirtualHosts">
<array type="java.lang.String">
<item>staticsite.com</item>
<item>www.staticsite.com</item>
<item>anotherdomainforstaticsite.com</item>
<item>www.anotherdomainforstaticsite.com</item>
</array>
</set>
</set>
</configure>
So the following mappings are now taking place:
webappsite.com/ --> jetty/webapps/ROOT.war
webappsite.com/web --> sites/webappsite.com/web
staticsite.com/ --> sites/staticsite.com/
This seems to have done the trick!

Tuesday, February 24, 2009

Configuring SSH for behind a firewall

My brother couldn't get connected to his websites in Fetch on his Mac and we figured out that the library he was at was blocking most ports except the most common ones. His VPS only allows connections via SSH/SCP/SFTP or HTTP. In the end, I configured sshd on his VPS to listen to port 21 (the standard FTP port) as well as port 22. Since FTP isn't running on his VPS, this worked fine. Then he configured Fetch to connect on port 21 and all was good.

To configure sshd on his VPS, I edited /etc/ssh/sshd_config and added the following lines:
Port 22
Port 21
Then I restarted sshd:
service sshd restart
That's all there was to it!
 

Labels

Labels