Sidenote

  • Random
  • Archive
  • RSS
  • Ask me anything

The usual virtualenv/Django/gunicorn/nginx howto … from my perspective

Install nginx

sudo apt-get install nginx

Install distribute (the new hotness!)

curl -O http://python-distribute.org/distribute_setup.py

python distribute_setup.py

Install pip (the new hotness!)

easy_install pip

Install virtualenv (all time hotness)

pip install virtualenv

Create Virtual Environment

virtualenv —no-site-packages —distribute env_my_application

Activate Virtual Environment

source /home/user/env_my_application/bin/activate

Install required packages

pip install Django

pip install gunicorn

or if you already have a requirements.txt file

pip install -r requirements.txt

Change to you Django application folder

cd /home/user/my_application/

Test Django Application with Gunicorn

gunicorn my_application.wsgi:application -b 0.0.0.0:8000

Create gunicorn script

vim /home/user/guni_my_application.sh

add the following code

#!/bin/bash

set -e

LOGFILE=/home/user/logs/gunicorn.log

LOGDIR=$(dirname $LOGFILE)

NUM_WORKERS=9 #1 + 2 * CPUs

# user/group to run as

USER= user

GROUP= user

ADDRESS=127.0.0.1:8000

cd /home/user/my_application

source /home/user/env_my_application/bin/activate

test -d $LOGDIR || mkdir -p $LOGDIR

exec gunicorn -w $NUM_WORKERS —bind=$ADDRESS \

  —user=$USER —group=$GROUP —log-level=debug \

  —log-file=$LOGFILE 2»$LOGFILE 

my_application.wsgi:application

give proper privileges with

sudo chmod ug+x  /home/user/guni_my_application.sh

Create nginx conf file for application

sudo vim /etc/nginx/sites-available/my_application.conf

add the following code

server {

    listen 80 default_server;

    #server_name my_application.mydomain.gr;

    access_log /home/user/logs/nginx.access.log;

    error_log /home/user/logs/nginx.error.log;

    location /static/ { # STATIC_URL

        alias /home/user/my_storage/my_application_static/static/; # STATIC_ROOT

        expires 30d;

    }

    location /media/ { # MEDIA_URL

        alias /home/user/my_storage/my_application_static/media/; # MEDIA_ROOT

        expires 30d;

    }

    location / {

        proxy_pass_header Server;

        proxy_set_header Host $http_host;

        proxy_redirect off;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Scheme $scheme;

        proxy_connect_timeout 10;

        proxy_read_timeout 10;

        proxy_pass http://localhost:8000/;

    }

}

Create symlink to sites-enabled folder

ln -s  /etc/nginx/sites-available/my_application.conf  /etc/nginx/sites-enabled/my_application.conf

Make sure that nginx has access to your folders (that is if you get an error 13: Permission denied). Check the user is running under at /etc/nginx/nginx.conf, line 1!

Reload nginx configuration

sudo nginx -s reload

Start your service

sudo service my_application start

Enjoy!!!

The above steps were executed on an Ubuntu 12.04 LTS x64 with a user account with sudo privileges. It should run without any problem in any system

Information gathered by the following resources and tutorials

  • https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/gunicorn/
  • https://code.djangoproject.com/wiki/DjangoAndNginx
  • http://docs.gunicorn.org/en/latest/run.html#gunicorn
  • http://senko.net/en/django-nginx-gunicorn/
    • #django
    • #python
    • #gunicorn
    • #nginx
    • #virtualenv
    • #distribute
    • #development
    • #howto
  • 1 month ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

How to solve “417 Expectation Failed” error on VS2012

If you happen to use Visual Studio 2012 and at the same time your company or your infrastructure uses the Squid proxy, then when you try to add a Visual Studio Extension you propably get the 417 Expectation Failed error.

The solution is to either add the ignore_expect_100 on line on the squid.conf file or add the following at you devenv.exe.conf file (near the end of file)

<system.net>

    <settings>

        <ipv6 enabled=”true”/>

        <servicePointManager expect100Continue=”false”/>

    </settings>

</system.net>

Source: sadev.co.za

    • #vs2012
    • #squid
    • #error
    • #417
    • #windows
  • 1 month ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

error: Unable to find vcvarsall.bat - Solution for the Visual Studio users

I admit it! I use a PC to write my Django apps. To be more accurate, I not only use a PC (instead of a MAC), I also run Windows 2008 Server on it and use VS2012 as my IDE! I know I must be something of a mad Microsoft fanboy, that buys anything Microsoft creates and adore Bill Gates as a god, or… I might just be reasonable.

The point is that I often have to install python packages that require compiling, such as the Python Imaging Library or ReportLab. If anyone has ever tried to install such libraries with either pip install pil or downloading the package and running setup.py install he may have received the message

error: Unable to find vcvarsall.bat

This message just states that he cannot find a compiler for the package. The solution is either installing MinGW32, or if you already have the VS2012 installed, use the VS compiler. If you want a permanent solution, then you have to add the System Variable VS90COMNTOOLS to point to the Visual Studio Common Tools folder. If you don’t know the Visual Studio Common Tools folder check the screenshot to where you can find it.

The quick solution would be to run

SET VS90COMNTOOLS=%VS110COMNTOOLS%

before runing the setup.py install or the pip install pil command.

System Variables

The screenshot is in Swedish and the windows titles are System Properties (Systemegenskaper) and Environment Variables (Miljövariabler)

 

    • #python
    • #pip
    • #PIL
    • #reportlab
    • #compiler
    • #windows
    • #vcvarsall.bat
  • 4 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

My view on NOT working on a MAC.

Working with Python, Django, virtualenv and GIT on a Windows PC with PowerShell is … like working on a Mac except you have spent less money!!!

Thank to

  • Microsoft for PowerShell
  • Guido for Python
  • Adrian and Jacob for Django
  • Ian for virtualenv
  • Linus for GIT
  • GitHub for GitHub for Windows
    • #python
    • #mac
    • #powershell
    • #virtualenv
    • #git
    • #django
  • 5 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

IFTTT Blog: The New IFTTT

ifttt:

Over the past few months, our team has been working hard to improve your experience with IFTTT. We’re proud to announce a new look, new language, new Channels, and speedier Triggers!

Logo

A New Look

Our new logo and wordmark come from the idea that the combination of two basic elements can…

  • 11 months ago > ifttt
  • 528
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

What to do when your AD Domain account gets locked out periodically after changing your password

There is only 2 simple steps you should perform

  1. Find the offending PC or Server (the PC or the Server, where from the account is not authenticating)
  2. After finding the PC or Server, change the password at the application that still hold the old password

Step 1: You need to enable Failure Audit for accounts at your DC or DCs.

The Audit Policy settings are located in the Default Domain policy settings. To view the Auditing policy settings, in the Group Policy MMC, double-click Computer Configuration, double-click Windows Settings, double-click Security Settings, double-click Local Policies, and then double-click Audit Policy.

You may also find extremely useful the Account Lockout and Management Tools and this and this post.

Step 2: After you have found the problematic PC you have probably found whether is an application or a mapped share that is causing the problem. If it is an application, just update its settings. If it is a share, just run rundll32.exe keymgr.dll,KRShowKeyMgr to access the Stored User Names and Passwords.

You may find useful this post.


    • #windows 2003
    • #Windows
    • #windows server
    • #account
    • #lockout
    • #tip
    • #troubleshooting
    • #administration
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Why you should NEVER name you local AD Domain the same as your Internet Domain?

Because then you have to ssh to your US based server in order to ssh to your GR based Home Server whose domain name is the same as your AD domain!

#bad_practice

  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
lynchlegion:

Amazing programming joke. xD
Pop-upView Separately

lynchlegion:

Amazing programming joke. xD

(via myconsole)

Source: jonhollow

  • 1 year ago > jonhollow
  • 747
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Running Django on Windows (with performance tests)

Django, RoR, Node.js, MongoDB, Sinatra, Twisted for the unrepentant Windows Server 2008 / IIS7 user and or administrator.

  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Det har hänt på mig många gånger! 
View Separately

Det har hänt på mig många gånger! 

(via myconsole)

Source: programmer-problems

    • #funny
    • #programming
  • 1 year ago > programmer-problems
  • 78
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Page 1 of 10
← Newer • Older →

Logo

Follow Nikolas Demiridis on Quora

This actually started as a way to post (and archive) anything I was finding to be insteresting enough. Now it actually serves as a kind of memo notes to myself.
This is an English language blog.

Me, Elsewhere

  • @nikolasd on Twitter
  • Facebook Profile
  • nikolasv on Youtube
  • skroutz on Flickr
  • nikolasd on Delicious
  • nikolasd on Foursquare
  • My Skype Info
  • Linkedin Profile
  • nikolasd on github

Twitter

loading tweets…

I Dig These Posts

  • Photo via myconsole

    lynchlegion:

    Amazing programming joke. xD

    Photo via myconsole
  • Post via katerinam
    On "I am Hellene"

    Thank you everyone, for following, sharing, thank you for the critics, thank you for subscribing, sending messages, thank you for...

    Post via katerinam
  • Photo via myconsole

    “How my boyfriend planned our double date with his friend…”

    Photo via myconsole
  • Photo via timemagazine

    TIME’s 2011 Person of the Year is The Protester

    Photo via timemagazine
See more →
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Greece License.

Effector Theme by Pixel Union