ForeverYoung's blog ยป blohg/atom/blohg/?lang=en2012-02-15T06:18:37ZAnton NovosyolovLinux, programming, etc.blohgMoving to Nginx and Gunicorn/post/nginx-gunicorn/?lang=en2012-02-15T06:18:37Z2012-02-15T06:18:37ZAnton Novosyolovanton.novosyolov@gmail.com<!-- tags: nginx,gunicorn,blohg,selectel,cloud,hosting,moving -->
<p><a class="reference external" href="http://translate.google.com/translate?sl=ru&tl=en&js=n&prev=_t&hl=ru&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fselectel.ru%2Fnews%2Fresumption-and-updating-of-cloud-server-service%2F&act=url">Selectel resumed cloud server service selectel</a>,
so I decided to create new server in new server pool and also move from lighttpd to nginx.</p>
<!-- tags: nginx,gunicorn,blohg,selectel,cloud,hosting,moving -->
<p><a class="reference external" href="http://translate.google.com/translate?sl=ru&tl=en&js=n&prev=_t&hl=ru&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fselectel.ru%2Fnews%2Fresumption-and-updating-of-cloud-server-service%2F&act=url">Selectel resumed cloud server service selectel</a>,
so I decided to create new server in new server pool and also move from lighttpd to nginx.</p>
<!-- read_more -->
<p>Server is running on Debian Squeeze Mini.</p>
<div class="section" id="installation">
<h3>Installation</h3>
<p>Nginx is installed from squeeze-backports repository.</p>
<p>From root:</p>
<pre class="brush: bash">
echo "# squeeze-backports" >> /etc/apt/sources.list
echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list
apt-get update
apt-get -t squeeze-backports install nginx
</pre>
<p>For controlling server processes install <a class="reference external" href="http://supervisord.org">supervisord</a>:</p>
<pre class="brush: bash">
apt-get install supervisor
</pre>
<p>Install virtualenv and mercurial:</p>
<pre class="brush: bash">
apt-get install virtualenv
apt-get install mercurial
</pre>
</div>
<div class="section" id="creating-user-and-setting-up-virtualenv">
<h3>Creating user and setting up virtualenv</h3>
<pre class="brush: bash">
useradd -m -s /bin/bash blog
su blog
</pre>
<p>From blog user:</p>
<pre class="brush: bash">
cd ~
virtualenv env
cd env
. bin/activate
</pre>
<p>Under env:</p>
<pre class="brush: bash">
easy_install pip
pip install gunicorn
</pre>
</div>
<div class="section" id="install-blohg">
<h3>Install blohg</h3>
<p>I use customized version, so I get it from my <a class="reference external" href="https://bitbucket.org/ForeverYoung/blohg">repository</a> (under env):</p>
<pre class="brush: bash">
cd ~
hg clone https://bitbucket.org/ForeverYoung/blohg
cd blohg
python setup.py install
</pre>
<p>If there is an error while installing, install gcc and python-dev (under root):</p>
<pre class="brush: bash">
apt-get install gcc
apt-get install python-dev
</pre>
<p>For stock version (under env):</p>
<pre class="brush: bash">
pip install blohg
</pre>
</div>
<div class="section" id="configuring-gunicorn">
<h3>Configuring gunicorn</h3>
<p>Create <em>blog_app.py</em> in <em>~blog</em>:</p>
<pre class="brush: python">
#!/usr/bin/python
from blohg import create_app
app = create_app("/home/blog/blog")
</pre>
<p>Clone your blog to server (as <a class="reference external" href="http://docs.blohg.org/deploy/#using-a-wsgi-app">here</a>):</p>
<pre class="brush: bash">
hg clone my_blohg ssh://blog@yourdomain.tld/home/blog/blog/
</pre>
<p>Create <em>gunicorn.conf.py</em> in <em>~blog</em>:</p>
<pre class="brush: python">
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
bind = "unix:/home/blog/blog.socket"
pidfile = "/home/blog/blog.pid"
logfile = "/home/blog/logs/gunicorn.log"
loglevel = "info"
proc_name = "blog"
user = "www-data"
group = "www-data"
</pre>
</div>
<div class="section" id="configuring-supervisor">
<h3>Configuring supervisor</h3>
<p>Create <em>/etc/supervisor/conf.d/blog.conf</em>:</p>
<pre class="brush: plain">
[program:blog]
command = /home/blog/env/bin/gunicorn blog_app:app -c /home/blog/gunicorn.conf.py
directory = /home/blog/
autostart = true
autorestart = true
redirect_stderr = true
daemon = false
debug = false
logfile = /home/blog/logs/supervisor.log
loglevel = "info"
user = "www-data"
</pre>
<p>Start supervisor:</p>
<pre class="brush: bash">
/etc/init.d/supervisor start
</pre>
</div>
<div class="section" id="configuring-nginx">
<h3>Configuring nginx</h3>
<p>Create <em>/etc/nginx/sites-available/blog</em>:</p>
<pre class="brush: plain">
server {
listen 80;
server_name yourdomain.tld;
access_log /home/blog/logs/nginx_access.log;
error_log /home/blog/logs/nginx_error.log;
location / {
proxy_pass http://unix:/home/blog/blog.socket;
include proxy_params;
}
}
</pre>
<p>Create link in <em>sites-enabled</em>:</p>
<pre class="brush: bash">
cd /etc/nginx/sites-enabled
ln -s ../sites-available/blog blog
</pre>
<p>Start nginx:</p>
<pre class="brush: bash">
/etc/init.d/nginx start
</pre>
<p><em>That's all!</em></p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script></div>
About blohg/post/about-blohg/?lang=en2011-05-27T10:24:15Z2011-05-27T10:24:15ZAnton Novosyolovanton.novosyolov@gmail.com<!-- date: 1306491855 -->
<!-- tags: python,reStructuredText,mercurial,gentoo,lighttpd,blohg -->
<p><a class="reference external" href="http://blohg.org">Blohg</a> is a blog engine written in Python.</p>
<!-- date: 1306491855 -->
<!-- tags: python,reStructuredText,mercurial,gentoo,lighttpd,blohg -->
<p><a class="reference external" href="http://blohg.org">Blohg</a> is a blog engine written in Python.</p>
<!-- read_more -->
<p>It has <a class="reference external" href="http://flask.pocoo.org">Flask</a>, <a class="reference external" href="http://jinja.pocoo.org/2/">Jinja2</a>, <a class="reference external" href="http://pypi.python.org/pypi/docutils">docutils</a>, <a class="reference external" href="http://mercurial.selenic.com">Mercurial</a> in its basis.
Comment system is external, via <a class="reference external" href="http://disqus.com">disqus</a>.</p>
<p>For me it has this advantages:</p>
<ul class="simple">
<li><a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> - it has more capabilities than, for example, <a class="reference external" href="http://ru.wikipedia.org/wiki/Markdown">Markdown</a>.</li>
<li><a class="reference external" href="http://mercurial.selenic.com">Mercurial</a> - It's convinient to post - <em>edit</em>, hg commit, hg push (but there's no capability to post from browser <em>yet</em>, probably I will make this possible).</li>
</ul>
<div class="section" id="installation">
<h3>Installation</h3>
<p>I don't like to describe how to install something, but in gentoo it's just one command (<a class="reference external" href="http://rafaelmartins.eng.br">Rafael G. Martins</a> - author of blohg - is gentoo developer) (<em>while I looked at his site, I saw many goodies, I'll try to get to know them and describe here</em>):</p>
<pre class="brush: bash">
$ emerge blohg
</pre>
</div>
<div class="section" id="usage">
<h3>Usage</h3>
<p>Create repository:</p>
<pre class="brush: bash">
$ blohg initrepo --repo-path my_blohg
</pre>
<p>Set up settings in <em>config.yaml</em>, tune up templates (in <em>templates</em> directory).</p>
<p>After that, write posts (in <em>content/post</em> directory), create attachments (in <em>content/attachments</em>) and commit changes.</p>
</div>
<div class="section" id="deploy">
<h3>Deploy</h3>
<p>Clone repo to remote host:</p>
<pre class="brush: bash">
$ hg clone my_blohg ssh://user@yourdomain.tld/path/to/my_blohg/
</pre>
<p>I use <a class="reference external" href="http://www.lighttpd.net">lighttpd</a> as web-server.</p>
<p><em>mod_fastcgi.conf</em>:</p>
<pre class="brush: plain">
fastcgi.debug = 0
fastcgi.server = ("/" =>
(
"blohg" => (
"socket" => "/tmp/blohg-fcgi.sock",
"bin-path" => "/var/www/blohg.fcgi",
"check-local" => "disable",
"fix-root-scriptname" => "enable"
)
)
)
alias.url = (
"/static/" => "/var/www/blog/static"
)
url.rewrite-once = (
"^(/static.*)$" => "$1",
"^(/favicon.ico.*)$" => "/static$1",
)
</pre>
<p>Contents of <em>/var/www/blohg.fcgi</em> (python module <a class="reference external" href="http://pypi.python.org/pypi/flup">flup</a> is needed):</p>
<pre class="brush: python">
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from blohg import create_app
if __name__ == '__main__':
application = create_app('/path/to/my_blohg')
WSGIServer(application).run()
</pre>
</div>
<div class="section" id="improvements">
<h3>Improvements</h3>
<div class="class strikeout container">
<p>In <a class="reference external" href="/post/my-server/?lang=en">post about my server</a> I wanted to make strikeout text,
but sadly reStructuredText don't support that.
I patched docutils, <a class="reference external" href="http://blog.f-y.name/attachments/docutils-0.7-strikeout.patch">here's a patch</a>.
But I want to move this functionality to blohg.</p>
<p><strong>UPD</strong>: Done, <a class="reference external" href="http://hg.f-y.name/blohg/changeset/c82ba2f18ad9">changeset</a>.</p>
</div>
<p><strong>UPD2</strong>: Done properly. <a class="reference external" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#custom-interpreted-text-roles">There is</a> standard way to define custom roles which only adds class to <span> tag:</p>
<pre class="brush: plain">
.. role:: strikeout
:class: strikeout
</pre>
<p>Or you can add a block to container with strikeout class:</p>
<pre class="brush: plain">
.. container::
:class: strikeout
</pre>
<p>I made a fork of blohg on <a class="reference external" href="http://bitbucket.org">http://bitbucket.org</a>, to publish my changes: <a class="reference external" href="http://hg.f-y.name/blohg">fork</a>.
More precisely, I made a fork of Ry4an's repository, because Rafael serves hg repository from his own server.</p>
<p>Looked at <a class="reference external" href="http://hg.rafaelmartins.eng.br/rst-resume/">rst-resume</a>, I want to publish my resume at this site.</p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script></div>