From a80a0b66556603af4e900fc4150fe5a62f04a07f Mon Sep 17 00:00:00 2001 From: kirsle Date: Thu, 11 Sep 2014 22:53:12 -0700 Subject: [PATCH] Created Server Configuration (markdown) --- Server-Configuration.md | 130 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Server-Configuration.md diff --git a/Server-Configuration.md b/Server-Configuration.md new file mode 100644 index 0000000..6fe193a --- /dev/null +++ b/Server-Configuration.md @@ -0,0 +1,130 @@ +# Config File + +Copy the file `config-sample.py` as a file named `config.py`, and edit its contents to set up your site. It's very important that you change the `SECRET_KEY` variable, as this is used to sign the session cookies and +prevent people from tampering with them. The config script is well-documented with comments explaining what all the options do. + +# Apache Configurations + +## mod_wsgi + +For simple sites you can configure Rophako to run as a mod_wsgi app. + +In your Apache configuration: + +```apache + + ServerName www.example.com + WSGIDaemonProcess rophako user=www-data group=www-data threads=5 home=/home/www-data/git/rophako + WSGIScriptAlias / /home/www-data/git/rophako/app.wsgi + WSGIScriptReloading On + CustomLog /home/www-data/logs/access_log combined + ErrorLog /home/www-data/logs/error_log + + + WSGIProcessGroup rophako + WSGIApplicationGroup %{GLOBAL} + Order allow,deny + Allow from all + + +``` + +A file named `app.wsgi` is included in the git repo. Here it is for reference. You may need to make changes to it if you use a different virtualenv: + +```python +#!/usr/bin/env python + +"""WSGI runner script for the Rophako CMS.""" + +import sys +import os + +# Add the CWD to the path. +sys.path.append(".") + +# Use the 'rophako' virtualenv. +activate_this = os.environ['HOME']+'/.virtualenv/rophako/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) + +from rophako import app as application + +# vim:ft=python +``` + +## mod_fcgid and mod_rewrite + +For Kirsle.net I had a legacy document root full of random static files, so Rophako needed to serve the dynamic pages but let Apache serve all the legacy stuff. + +Apache configuration: + +```apache +# Rophako www.kirsle.net + + ServerName www.kirsle.net + DocumentRoot /home/kirsle/www + CustomLog /home/kirsle/logs/access_log combined + ErrorLog /home/kirsle/logs/error_log + SuexecUserGroup kirsle kirsle + + + Options Indexes FollowSymLinks ExecCGI + AllowOverride All + Order allow,deny + Allow from all + + + + SetHandler fcgid-script + Options +ExecCGI + AllowOverride all + Order allow,deny + Allow from all + + +``` + +And in my `.htaccess` file in my document root: + +```apache + + RewriteEngine on + RewriteBase / + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.*)$ /fcgi/index.fcgi/$1 [QSA,L] + RewriteRule ^$ /fcgi/index.fcgi/ [QSA,L] + +``` + +And finally, my FastCGI script. Important things to note: + +* The shebang line points to the Python binary in my virtualenv. +* I modify `sys.path` and `chdir` to my git checkout folder for Rophako. +* The `ScriptNameStripper` allows `mod_rewrite` to work best. Without it you'll sometimes get URL paths like `/fcgi/index.fcgi/blog/entry/...` etc. from Flask because that's what it thinks its path is. + +```python +#!/home/kirsle/.virtualenv/rophako/bin/python + +import os +import sys +sys.path.append("/home/kirsle/git/rophako") +os.chdir("/home/kirsle/git/rophako") + +from flup.server.fcgi import WSGIServer +from rophako import app + +class ScriptNameStripper(object): + def __init__(self, app): + self.app = app + + def __call__(self, environ, start_response): + environ["SCRIPT_NAME"] = "" + return self.app(environ, start_response) + +app = ScriptNameStripper(app) + +if __name__ == "__main__": + WSGIServer(app).run() +``` + +**Next Step:** [[Configuration and Plugins]] \ No newline at end of file