Skip to content
This repository
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors

Showing 1 changed file with 65 additions and 9 deletions. Show diff stats Hide diff stats

  1. 74  docs/deploying/fastcgi.rst
74  docs/deploying/fastcgi.rst
Source Rendered
@@ -51,6 +51,64 @@ can execute it:
51 51
 
52 52
     # chmod +x /var/www/yourapplication/yourapplication.fcgi
53 53
 
  54
+Configuring Apache
  55
+------------------
  56
+
  57
+The example above is good enough for a basic Apache deployment but your `.fcgi`
  58
+file will appear in your application URL
  59
+e.g. example.com/yourapplication.fcgi/news/. There are few ways to configure
  60
+your application so that yourapplication.fcgi does not appear in the URL. A
  61
+preferable way is to use the ScriptAlias configuration directive::
  62
+
  63
+    <VirtualHost *>
  64
+        ServerName example.com
  65
+        ScriptAlias / /path/to/yourapplication.fcgi/
  66
+    </VirtualHost>
  67
+
  68
+If you cannot set ScriptAlias, for example on an shared web host, you can use
  69
+WSGI middleware to remove yourapplication.fcgi from the URLs. Set .htaccess::
  70
+
  71
+    <IfModule mod_fcgid.c>
  72
+       AddHandler fcgid-script .fcgi
  73
+       <Files ~ (\.fcgi)>
  74
+           SetHandler fcgid-script
  75
+           Options +FollowSymLinks +ExecCGI
  76
+       </Files>
  77
+    </IfModule>
  78
+
  79
+    <IfModule mod_rewrite.c>
  80
+       Options +FollowSymlinks
  81
+       RewriteEngine On
  82
+       RewriteBase /
  83
+       RewriteCond %{REQUEST_FILENAME} !-f
  84
+       RewriteRule ^(.*)$ yourapplication.fcgi/$1 [QSA,L]
  85
+    </IfModule>
  86
+
  87
+Set yourapplication.fcgi::
  88
+
  89
+    #!/usr/bin/python
  90
+    #: optional path to your local python site-packages folder
  91
+    import sys
  92
+    sys.path.insert(0, '<your_local_path>/lib/python2.6/site-packages')
  93
+
  94
+    from flup.server.fcgi import WSGIServer
  95
+    from yourapplication import app
  96
+
  97
+    class ScriptNameStripper(object):
  98
+       to_strip = '/yourapplication.fcgi'
  99
+
  100
+       def __init__(self, app):
  101
+           self.app = app
  102
+
  103
+       def __call__(self, environ, start_response):
  104
+           environ['SCRIPT_NAME'] = ''
  105
+       return self.app(environ, start_response)
  106
+
  107
+    app = ScriptNameStripper(app)
  108
+
  109
+    if __name__ == '__main__':
  110
+        WSGIServer(app).run()
  111
+
54 112
 Configuring lighttpd
55 113
 --------------------
56 114
 
@@ -73,17 +131,15 @@ A basic FastCGI configuration for lighttpd looks like that::
73 131
         "^(/static.*)$" => "$1",
74 132
         "^(/.*)$" => "/yourapplication.fcgi$1"
75 133
 
76  
-Remember to enable the FastCGI, alias and rewrite modules. This
77  
-configuration binds the application to `/yourapplication`.  If you want
78  
-the application to work in the URL root you have to work around a
79  
-lighttpd bug with the
  134
+Remember to enable the FastCGI, alias and rewrite modules. This configuration
  135
+binds the application to `/yourapplication`.  If you want the application to
  136
+work in the URL root you have to work around a lighttpd bug with the
80 137
 :class:`~werkzeug.contrib.fixers.LighttpdCGIRootFix` middleware.
81 138
 
82 139
 Make sure to apply it only if you are mounting the application the URL
83  
-root. Also, see the Lighty docs for more information on `FastCGI and
84  
-Python <http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModFastCGI>`_
85  
-(note that explicitly passing a socket to run() is no longer necessary).
86  
-
  140
+root. Also, see the Lighty docs for more information on `FastCGI and Python
  141
+<http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModFastCGI>`_ (note that
  142
+explicitly passing a socket to run() is no longer necessary).
87 143
 
88 144
 Configuring nginx
89 145
 -----------------
@@ -97,7 +153,7 @@ A basic flask FastCGI configuration for nginx looks like this::
97 153
     location /yourapplication { try_files $uri @yourapplication; }
98 154
     location @yourapplication {
99 155
         include fastcgi_params;
100  
-	fastcgi_split_path_info ^(/yourapplication)(.*)$;
  156
+        fastcgi_split_path_info ^(/yourapplication)(.*)$;
101 157
         fastcgi_param PATH_INFO $fastcgi_path_info;
102 158
         fastcgi_param SCRIPT_NAME $fastcgi_script_name;
103 159
         fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;

No commit comments for this range

Something went wrong with that request. Please try again.