Skip to content

Commit 34380b9

Browse files
vpestovnikovrduplain
authored andcommitted
Add detailed Apache httpd fastcgi configuration.
1 parent a3cb2a3 commit 34380b9

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

docs/deploying/fastcgi.rst

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,61 @@ can execute it:
5151

5252
# chmod +x /var/www/yourapplication/yourapplication.fcgi
5353

54+
Configuring Apache
55+
------------------
56+
57+
The example above is good enough for a basic Apache deployment but your `.fcgi` file will appear in your application URL e.g. www.example.com/yourapplication.fcgi/news/. There are few ways to resolve it. A preferable way is to use Apache ScriptAlias configuration directive::
58+
59+
<VirtualHost *>
60+
ServerName example.com
61+
ScriptAlias / /path/to/yourapplication.fcgi/
62+
</VirtualHost>
63+
64+
Another way is to use a custom WSGI middleware. For example on a shared web hosting::
65+
66+
.htaccess
67+
68+
<IfModule mod_fcgid.c>
69+
AddHandler fcgid-script .fcgi
70+
<Files ~ (\.fcgi)>
71+
SetHandler fcgid-script
72+
Options +FollowSymLinks +ExecCGI
73+
</Files>
74+
</IfModule>
75+
76+
<IfModule mod_rewrite.c>
77+
Options +FollowSymlinks
78+
RewriteEngine On
79+
RewriteBase /
80+
RewriteCond %{REQUEST_FILENAME} !-f
81+
RewriteRule ^(.*)$ yourapplication.fcgi/$1 [QSA,L]
82+
</IfModule>
83+
84+
yourapplication.fcgi
85+
86+
#!/usr/bin/python
87+
#: optional path to your local python site-packages folder
88+
import sys
89+
sys.path.insert(0, '<your_local_path>/lib/python2.6/site-packages')
90+
91+
from flup.server.fcgi import WSGIServer
92+
from yourapplication import app
93+
94+
class ScriptNameStripper(object):
95+
to_strip = '/yourapplication.fcgi'
96+
97+
def __init__(self, app):
98+
self.app = app
99+
100+
def __call__(self, environ, start_response):
101+
environ['SCRIPT_NAME'] = ''
102+
return self.app(environ, start_response)
103+
104+
app = ScriptNameStripper(app)
105+
106+
if __name__ == '__main__':
107+
WSGIServer(app).run()
108+
54109
Configuring lighttpd
55110
--------------------
56111

@@ -84,7 +139,6 @@ root. Also, see the Lighty docs for more information on `FastCGI and
84139
Python <http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModFastCGI>`_
85140
(note that explicitly passing a socket to run() is no longer necessary).
86141

87-
88142
Configuring nginx
89143
-----------------
90144

@@ -97,7 +151,7 @@ A basic flask FastCGI configuration for nginx looks like this::
97151
location /yourapplication { try_files $uri @yourapplication; }
98152
location @yourapplication {
99153
include fastcgi_params;
100-
fastcgi_split_path_info ^(/yourapplication)(.*)$;
154+
fastcgi_split_path_info ^(/yourapplication)(.*)$;
101155
fastcgi_param PATH_INFO $fastcgi_path_info;
102156
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
103157
fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
@@ -160,4 +214,4 @@ python path. Common problems are:
160214
.. _nginx: http://nginx.org/
161215
.. _lighttpd: http://www.lighttpd.net/
162216
.. _cherokee: http://www.cherokee-project.com/
163-
.. _flup: http://trac.saddi.com/flup
217+
.. _flup: http://trac.saddi.com/flup

0 commit comments

Comments
 (0)