1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Documentation is now exhaustive and zerobin is apache friendly

This commit is contained in:
sam
2012-05-18 22:18:40 +02:00
parent 97935e51d3
commit a3dcbe9c2b
40 changed files with 1100 additions and 149 deletions

View File

@ -2,8 +2,7 @@
Apache setup
=============
Apache is slower, heavier and more complicated to setup than Nginx. But it's also
much more famous:
Apache is heavier than Nginx. But it's also much more famous:
- more people will be able to help you on forums;
- your hosting will most probably support Apache;
@ -33,7 +32,65 @@ the setup of the Apache module mod_wsgi. If you don't know how to do this, or
if you can't do it (E.G: your hosting won't let you), you need to go for
the CGI setup.
==========
First, make sure you have mod_wsgi installed and enable by running (as admin)::
This setup is considered as slow, but you will still benefit from Apache
robustness.
a2enmod wsgi
This enable mod_wsgi. It it doesn't, install it first (on ubuntu, the package
is libapache2-mod-wsgi).
Then create an Apache configuration file, usually in /etc/apache/sites-available/.
Name it zerobin::
<VirtualHost *:80>
ServerName www.yourwebsite.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /path/to/zerobin/app.wsgi
<Directory /path/to/zerobin/zerobin/>
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Activate the website (as admin)::
a2ensite zerobin
And reload the apache configuration (as admin)::
service apache2 reload
You'll note that we refer to a file named app.wsgi. It's a Python file
creating the application Apache is going to use to start the Python process::
import os, sys
# make sure the zerobin module is in the PYTHON PATH and importable
ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, ZEROBIN_PARENT_DIR)
# create the wsgi callable
from zerobin.routes import get_app
settings, application = get_app(compressed_static=True)
You can of course create your own, as the `get_app` function is the only
way to pass settings to 0bin with this setup. You would do this by creating
a configuration file and passing it to the function::
import os, sys
ZEROBIN_PARENT_DIR = '/path/to/zerobin/parent/dir'
sys.path.insert(0, ZEROBIN_PARENT_DIR)
from zerobin.routes import get_app
settings, application = get_app(settings_file='/path/to/settings.py')
CGI
===
You can also run 0bin using CGI, but infortunaly we didn't have time to cover
it yet. Please contact us if you ever get the need to use it.

View File

@ -51,9 +51,51 @@ installing it.
Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually
go into /etc/nginx/conf.d/. Name it zerobin.conf.
The minimal file to run the site is:
The minimal configuration file to run the site is::
But you can make some adjustement to get better perfomances:
server {
listen 80;
server_name www.yourwebsite.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
`proxy_pass` just passes the external request to the Python process.
The port much match the one used by the 0bin process of course.
You can make some adjustements to get a better user experience::
server {
listen 80;
server_name www.yourwebsite.com;
location /favicon.ico {
root /path/to/zerobin/static/img;
}
location /static/ {
root /path/to/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}
This make Nginx serve the favicon and static files, set the expire HTTP headers
and make sure gzip compression is used with browsers that support it.

View File

@ -1,15 +1,3 @@
--host=STR
The host on which to listen for incomming request. Usually 127.0.0.1 to
listen locally or 0.0.0.0 to listen from the outside.
Default: 127.0.0.1
Setting file : HOST
============
Options
============

View File

@ -2,9 +2,9 @@
Theming
=======
0bin comes a complete theming support, but for now it's not well ingrated.
0bin comes with a complete theming support, but for now it's not well integrated.
If you wish to create your own theme, you'll need to create template similar
If you wish to create your own theme, you'll need to create templates similar
to the ones in zerobin/view, and add the path to the director containing them
to the settings file.

View File

@ -1,3 +1,72 @@
====================
=================
Using supervisor
====================
=================
Supervisor is a very nice way to manage you Python processes. We won't cover
the setup (which is just apt-get install supervisor or pip install supervisor
most of the time), but here is a quick overview on how to use it.
Create a configuration file named supervisor.ini::
[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/path/to/zerobin/zerobin.py --port 80 --compressed-static
directory=/path/to/zerobin/
environment=PYTHONPATH='/path/to/zerobin/'
user=zerobin
autostart=true
autorestart=true
The 4 first entries are just boiler plate to get you started, you can copy
them verbatim.
The last one define one (you can have many) process supervisor should manage.
It means it will run the command::
/path/to/zerobin/zerobin.py --port 80 --compressed-static
In the directory, with the environnement and the user you defined.
This command will be ran as a daemon, in the background.
`autostart` and `autorestart` just make it fire and forget: the site will always be
running, even it crashes temporarly or if you retart the machine.
The first time you run supervisor, pass it the configuration file::
supervisord -c /path/to/supervisor.ini
Then you can manage the process by running::
supervisorctl -c /path/to/supervisor.ini
It will start a shell from were you can start/stop/restart the service
You can read all errors that might occurs from /tmp/zerobin.log.
.. Note::
If you installed zerobin in a virtualenv, you may set the command
to run directly from it::
command=/path/to/virtualenv/bin/zerobin --port 80 --compressed-static