ForeverYoung's blog ยป hosting/atom/hosting/?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>
Hosting moved to selectel cloud/post/move-to-selectel/?lang=en2011-07-19T09:24:28Z2011-07-19T09:24:28ZAnton Novosyolovanton.novosyolov@gmail.com<!-- tags: hosting,cloud,selectel,moving -->
<p>As my server is gone down suddenly and I don't have a chance to find out what is with it, I decided to move my blog to cloud platform.</p>
<p>I chose <a class="reference external" href="http://selectel.ru">Selectel</a> as hosting provider. Prices start from 50 roubles (about $1.85), this is only for keeping virtual machine for month, without running it. For my blog traffic (almost 0 :) ) overall price will be about 70 roubles (about $2.60) per month, it's very cheap I think.</p>
<p><strong>UPD</strong>: After month usage, actual price is about 44 roubles (about $1.57).</p>
<!-- tags: hosting,cloud,selectel,moving -->
<p>As my server is gone down suddenly and I don't have a chance to find out what is with it, I decided to move my blog to cloud platform.</p>
<p>I chose <a class="reference external" href="http://selectel.ru">Selectel</a> as hosting provider. Prices start from 50 roubles (about $1.85), this is only for keeping virtual machine for month, without running it. For my blog traffic (almost 0 :) ) overall price will be about 70 roubles (about $2.60) per month, it's very cheap I think.</p>
<p><strong>UPD</strong>: After month usage, actual price is about 44 roubles (about $1.57).</p>