<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tadhg.com &#187; pylons</title>
	<atom:link href="http://tadhg.com/wp/tag/pylons/feed/" rel="self" type="application/rss+xml" />
	<link>http://tadhg.com/wp</link>
	<description>Wherein some things Tadhg are discussed</description>
	<lastBuildDate>Wed, 08 Sep 2010 03:20:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pylons Via Apache Port Issues</title>
		<link>http://tadhg.com/wp/2009/06/12/pylons-via-apache-port-issues/</link>
		<comments>http://tadhg.com/wp/2009/06/12/pylons-via-apache-port-issues/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 00:42:14 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=1792</guid>
		<description><![CDATA[I&#8217;ve been using Pylons (and, more recently, the Pylons-based TurboGears 2.0) for various projects for a while, and a few weeks ago ran into an annoying and specific problem: using Pylons via Apache made Pylons occasionally think it was running on a different port.
There&#8217;s a relatively easy answer to this, but until I was reading [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://www.pylonshq.com/">Pylons</a> (and, more recently, the Pylons-based <a href="http://turbogears.org/2.0/">TurboGears 2.0</a>) for various projects for a while, and a few weeks ago ran into an annoying and specific problem: using Pylons via Apache made Pylons occasionally think it was running on a different port.</p>
<p>There&#8217;s a relatively easy answer to this, but until I was reading through TurboGears documentation, I didn&#8217;t find it.<br />
<span id="more-1792"></span><br />
The basic setup is this: I&#8217;m running my Pylons project on some arbitrary port, and I want to point some URL that Apache knows about from port 80 to that arbitrary port. I use a RewriteRule to do this, as follows.</p>
<p>Pylons development.ini:</p>
<pre class="php">
[server:main]
use = egg:Paste#http
host = sub.server.tld
port = 12345
</pre>
<p>apache.conf:</p>
<pre class="php">
&lt;VirtualHost *:80&gt;
ServerName sub.server.tld
RewriteEngine On
RewriteRule  ^/(.*) http://sub.server.tld:12345/$1 [P]
DocumentRoot /path/to/pylons/project
&lt;/VirtualHost&gt;
</pre>
<p>All that does is have Apache look for incoming port 80 requests to that subdomain and then pass them to that subdomain on port 12345, which is where the Pylons app is listening.</p>
<p>That works just fine until, for any reason, you have your Pylons project execute a local redirect, e.g. <code>redirect("/nextpage/")</code>. At this point Pylons will tell the browser to go to <code>http://sub.server.tld:12345/nextpage/</code>, which for me caused all kinds of problems.</p>
<p>Embarrassingly, I couldn&#8217;t find the answer to this problem, despite looking through everything I could find about where Pylons sets its host name and port in the environment, etc.</p>
<p>When I was setting up TurboGears 2, however, I noticed a reference to using TurboGears behind Apache as a reverse proxy, and instructions on doing that. The RewriteRule above is essentially doing exactly that, but I hadn&#8217;t thought of it in those terms. The reverse proxy instructions included how to deal with the port issues. There were a couple of further hiccups, but I ultimately got it working.</p>
<p>The Apache configuration stays the same, as does the <code>server:main</code> section of development.ini. Change the title of the <code>app:main</code> section to <code>app:pylons</code>. Then add the following to development.ini:</p>
<pre class="php">
[pipeline:main]
pipeline = proxy pylons

[filter:proxy]
use = egg:PasteDeploy#prefix
prefix = /
force_port:80
</pre>
<p>That&#8217;s it; <code>pipeline</code> tells it to run through proxy before running the pylons section (which is what used to be your <code>app:main</code> section), and the <code>filter:proxy</code> section tells it to force the port to 80.</p>
<p>The only other thing to remember is that now you have to run<br />
<code>paster setup-app development.ini#pylons</code><br />
instead of<br />
<code>paster setup-app development.ini</code></p>
<p>(Note that this is for small or in-development projects only&#8212;if you&#8217;re going to be running anything that requires better performance, paster behind an Apache Rewrite is probably not the way to go.)</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/apache/" rel="tag">apache</a>, <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/pylons/" rel="tag">pylons</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/web-development/" rel="tag">web-development</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/">Some Character Encoding Gotchas</a> <span class="related-post-date timestamp">Thu 16 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/09/pywebsf-meetup-for-sf-area-python-web-developers/">PyWebSF: Meetup for SF-Area Python Web Developers</a> <span class="related-post-date timestamp">Tue 09 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/05/16/sabbatical-close/">sabbatical.close()</a> <span class="related-post-date timestamp">Sun 16 May 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/04/29/improving-a-python-word-counting-function/">Improving a Python Word Counting Function</a> <span class="related-post-date timestamp">Thu 29 Apr 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/">WordPress 2.9 Upgrade</a> <span class="related-post-date timestamp">Sun 10 Jan 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/06/12/pylons-via-apache-port-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
