Tag Archives: nginx

Multiple Development Environments on One Domain

While it’s true that distributed development should be managed by source control, with each participating party pushing or issuing pull requests from within their own environments, this is sometimes not possible.

Participants might not be able to setup their own development environments in light of many possible reasons and limitations. So remote development environments are usually setup for such participants so that they can work on their own forks of a project without interfering with others’ work. S/FTP/S is usually used, due to their inability to use version control remotely.

Here’s an interesting strategy that came to mind that allows participants to have their own environments on one single domain, single server, with the ability to switch between them without having to edit their hosts files or any other magic.

Continue reading



Setting up Flask with nginx

I’ve decided to implement one of my next projects in Python. I picked Flask as my HTTP framework for its lightweight and unbinding design. It pretty much allows you to do everything at a low level, should you want to. And I do; I always prefer a low-level approach, without the bulkiness, APIs, configuration files, etc.

In any case, since my webserver of choice has long been nginx (built-in servers don’t impress me too much), having it serve Flask applications in a robust, reliable way was required. The instructions to marry nginx and Flask via uWSGI are quite clear. I compiled the uwsgi application container, read the docs and came up with the following startup command:

sudo uwsgi -s /tmp/uwsgi.application.sock --chdir /path/to/application -w application:app --uid "www-data" --gid "www-data" --touch-reload . --daemonize /var/log/uwsgi.log

The above is a development setting and will probably be very different in production. Since Flask doesn’t force any convention upon you, I picked the following project layout for now:

.
|-- application
|   |-- application.py
|   |-- models
|   |-- routes.py
|   `-- views
`-- static
    |-- favicon.ico
    |-- js
    |   `-- script.js
    `-- robots.txt

All Python code is in the application directory, where uwsgi runs it. Static files are a directory above that, and will be served as from there and not pollute the source tree. I could have kept the static directory under application just as well, but I’ll keep it outside for now. Here’s what I came up for my

server {

    listen 80;
    server_name application.lo www.application.lo;

    root /path/to/application.lo/application;

    try_files /../static/$uri @application;

    location @application {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.application.sock;
    }

}

This is quite suitable for now. Any recommendations?