Ubuntu (10.04 LTS) server new website setup: the useful commands

Add a group & user

$ groupadd my_group 
$ useradd my_username -d /var/www/my_folder
Then add the user to the group
$ usermod -G my_group my_username


Get a list of all existing users:

$ cat /etc/passwd | cut -d: -f1

Get a list of all existing groups:

$ cat /etc/group |cut -d: -f1

Running uWSGI with the right user and group

In this scenario, I use a socket to run my uWSGI instance. That socket must be located in a folder that have write access permission by your new user.

description "uWSGI server for mysite.com"
start on runlevel 2
stop on runlevel [016]
exec /usr/local/bin/uwsgi  \
--chdir=/var/www/mysite.com \
--virtualenv=/var/www/mysite.com \
--pythonpath=/var/www/mysite.com/mysiteproject \
--socket \
--env DJANGO_SETTINGS_MODULE=mysiteproject.settings.production \
--module 'django.core.handlers.wsgi:WSGIHandler()' \
--master \
--processes 1 \
--vacuum \
--max-requests 500 \
--logto /var/www/mysite.com/logs/wsgi.log \
--uid username \
--gid groupname

I'm using --uid and --gid to define the user & group that will run uWSGI. I'm running it with --master process so it can respawn processes if necessary.

Nginx setup with uWSGI

# Redirect from www to nothing if not accepting domain name only
server {
    server_name  www.mysite.com;
    rewrite ^(.*) http://mysite.com$1 permanent;
server {

    listen   80;
    server_name  mysite.com;
    error_log /var/www/mysite/logs/error.log;
    root   /var/www/mysite/;

    location /static/ {
        autoindex    off;
        root   /var/www/mysite/mysiteproject/;
    location / {
        include uwsgi_params;
        uwsgi_param     SCRIPT_NAME "";

< / >