---
title: "DJANGO Fastcgi配置"
author: "androider"
date: "2008-12-01T16:28:23Z"
tags: []
slug: "django-fastcgi"
draft: false
lastmod: "2008-12-01T16:28:23Z"
id: 284129
url: "https://androider.iteye.com/blog/284129"
---

The `FastCGIExternalServer`directive tells Apache how to find your FastCGI server. As the [FastCGIExternalServer docs](http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer) explain, you can specify either a `socket`or a `host`. Here are examples of both:

 

```
# Connect to FastCGI via a socket / named pipe.
FastCGIExternalServer /home/user/public_html/mysite.fcgi -socket /home/user/mysite.sock

# Connect to FastCGI via a TCP host/port.
FastCGIExternalServer /home/user/public_html/mysite.fcgi -host 127.0.0.1:3033
```

 The second step is telling Apache to use FastCGI for URLs that match a certain pattern. To do this, use the [mod\_rewrite](http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html) module and rewrite URLs to `mysite.fcgi`

In this example, we tell Apache to use FastCGI to handle any request that doesn't represent a file on the filesystem and doesn't start with `/media/`. This is probably the most common case, if you're using Django's admin site:

 

```
<VirtualHost 12.34.56.78>
  ServerName example.com
  DocumentRoot /home/user/public_html
  Alias /media /home/user/python/django/contrib/admin/media
  RewriteEngine On
  RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ /mysite.fcgi/$1 [QSA,L]
</VirtualHost>
```