Kartones Blog

Be the change you wanna see in this world

Basic Nginx snippets

I've recently migrated my hosting, finally severing all remaining ties with .NET after rewriting some remaining small experients and projects with Python. As I now have a full Linux instance to manage (at Amazon Lightsail, wanted to try it and looks I'm sticking with it), I've had to improve my Nginx skills from "barely make a site run under a Docker container" to "configure multiple static and dynamic sites running on different subdomains on the same machine". This post is a small recollection of things I needed to accomplish.

Error log default location:


Subsites inside the same root server block (note that alias paths end with / while a server root path do not):

location /mysubpath/ {
        alias /my/path/to/mysubpath/;
        try_files $uri $uri/index.html =404;

Note: It is easier to follow the recommended rule of one /etc/nginx/sites-available/<name> entry per site or subsite instead of having a root path + location and then children location with different subpaths (using alias). I made it work even combining uWSGI and static sites but the config files were more complex, so I reverted to everything in its single file with a single server block.

Proxy uWSGI Python apps through Nginx using system sockets (and as a bonus, disabling default Nginx index file matching):

index wontmatch;

location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/mysocketname.sock;

Protect password and similar sensible files from being served:

location ~ /\. { deny  all; }

Making all path files have a default MIME type (CSV in the example):

location /mycsvs/ {
    types    { }
    default_type text/comma-separated-values;

Protecting with basic authentication (sample tutorial):

auth_basic "Password required";
auth_basic_user_file /mypathtopasswordfile/.htpasswd;

Subdomain aliases:

server_name myalias1.name.com myalias2.name.com name.com;

Custom headers:

# only for success http responses
add_header X-Custom-Header a_value;

# all http responses
add_header X-Custom-Header a_value always;


location /cv {
    return 302 $scheme://portfolio.kartones.net/curriculumvitae/;


Fully removing Server header (not only Nginx version):

sudo apt-get update
sudo apt-get install nginx-extras

sudo vim /etc/nginx/nginx.conf

# inside `http {}` section add:
server_tokens off;
more_set_headers 'Server: ';

# Save, exit and:
sudo service nginx restart

GZip all statics (Javascript, CSS, etcetera), as by default only HTML and a few others get compressed:

sudo vim /etc/nginx/ngnix.conf

# Search for `gzip_types` and replace it by:
gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml;

Cache expiration rules for static content: Include or adapt expires.conf inside http, server or location config blocks:

location ~* \.(?:rss|atom)$ {
        expires 1h;
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|zip|svg|webm|htc)$ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
location ~* \.(?:css|js)$ {
        expires 1M;
        access_log off;

Serving Static Content: Official article, has interesting parameters if you serve big static content files (pdfs, zips and the like).

Book Review: Can holding a fart kill you?

Different book today, read recently this christmas.


Can holding a fart kill you?

Title: Can holding a fart kill you?

Author: Andrew Thompson

I've always loved science and learning where do things come from, how the work, etcetera. So I wanted to see if a "facts book" is interesting enough or not. The answer is that, while a quick read (few hours at most), it contains actually interesting questions (and answers) and not everything is as dull as the title suggests.

Some of the questions are myths, others mere history (of sentences, of events like Halloween...), other science or medicine. You can probably live without knowing them, but it wakes up your curiosity to learn more in general about life. Careful as not all the facts are for children, there are questions about drugs, guns and other violent topics.

Most descriptions are 3 small paragraphs long, and being varied topics you will surely skip some questions. I'd also would have prefered all more positive topics instead of the violence-related ones but... even so I think it adds value to general knowledge.

Recommended Articles - 2016/12/21

  • Tesla Self-Driving Demonstration: Despite the funny music, this video exemplifies why I'm happy to live in this era: Self-driving cars and how they "see" the world. Even if still has to improve, I'm amazed technology is at this stage.

  • Microsoft reboots war on sleep: Another misfortuned Microsoft campaign about Office 365, in which promotes working always, anywhere, even if they don't sleep. They should change that "creative" marketing department because it is getting quite some bad feedback...

  • Building and Motivating Engineering Teams: Based on three fundamental aspects:

    • Money
    • Purpose
    • Respect
  • Matrix Multiplication: Great website to learn or refresh matrix multiplications

  • Bruce Schneier: 'The internet era of fun and games is over': And sadly, is at least partially true, considering how inmature products that have software get to the market in general, I love technology but I'm quite reluctant to have any IoT device at home...

  • Neutralizing Intel’s Management Engine: One of those scary reads that make you not trust your computer... Didn't knew this event existed!

  • FunctionLength: Interesting opinion from the guru Fowler about writing short functions to increase legibility. Lately I'm adopting also this approach when I see either long or not easy to comprehend methods.

  • No, I have no side code projects to show you: Pretty similar to what happens to me, that my side-projects are quite small or dumb or useless, because I "work hard and go home" and when at home, not everything is coding. And it is good for mental health, I don't burnout, I do more tiny pet projects and experiments, I read more... So better focus on doing a good job and then do side-projects only if you really want to, not forcibly.

  • 'Clean your desk': My Amazon interview experience: Frightening interview story, which goes way beyond reasonable privacy limits (and anti-cheating measures). I wouldn't think a remote interview could go so bad, but on the other side, it is the clearest and quickest sign that you don't fit on that process.

  • What Makes A Senior Software Developer?: I fully agree with it, mostly because I've been on both sides of the scale (gut feeling and checklist based promotions) and both have those flaws and biasings. I won't spoil the advice of how to notice if somebody is senior to encourage reading the article, but I think it is a very good "metric".

  • On Being A Senior Engineer: Closely related with previous link, similar approach, easily summarized as "expect a “senior” engineer to be a mature engineer". But good insights and things to look at in the article, like "The Ten Commandments of Egoless Programming".

  • Geektyper: Funny but elaborated fake operating system UIs, like movie ones. You can type or open "apps" that do things on their own.

  • Work ethic has a lot more to do with showing up on time and being reliable than it does working 80 hours - @jasonfried

Pet project: Shopping Lists published

As I'm moving towards fully removing all .NET projects I had, I've spend some time migrating some C#/ASP.NET code over to Python + Flask. One of the projects that could be of some interest, if only as a sample of a simple Flask app and Python file I/O, is my Shopping Lists pet project.

It's a quick & dirty web solution but we use it at home almost daily so it serves its purpose. As at least my colleage @Saski asked me if I was going to publish the source code, now that it's migrated to Python, you can find it at my Github, alongside some simple instructions of how to setup and use it.


It was one of my new approaches to development, keeping things minimalistic and simple: the "database" are plain text files, it has minimal functionality but it works in mobile (as will be where it will be used most frequently), and while is not a code I would showcase, publishing it can help me in the future to remember some basic Flask routing and redirects syntax, reading and writing files, etcetera.

Software Developer Position for TheMotion

We are searching to fill a software developer position for my team at TheMotion.
Currently we have no open seats for tech recruitment, but I'll leave the description as it was a nice showcase of what we valued.

You can be senior or junior. Although the more experience the better, I don't care as long as you have some development knowledge, will to learn and an open mind (our system evolves fast). If you're senior you'll have more freedom, if you're more junior we'll guide you.

You should be a good team player (we don't want heroes, rockstars or similar buzzwords), and while we currently use Python 3, Docker and a bunch of AWS services, everything might change so there's no need to previously know about the specific languages and tools. In fact, at least half of tech employees joined the company not knowing Python.

You must like to do javascript, as our team currently is the "keeper" of most web services: public API, Web application, mailing, video distribution channels... We also setup the infrastructure for other web projects and APIs and help building and maintaining core platform services. We just do more javascript than the other teams, but not all the time, for example this past months we've done way more backend Python than JS. For the record, we currently use Ember.js 2.x and ES6.

You need to have a minimum level of english to understand and carry a basic conversation, but our British english teacher will help you improve no matter your level. This is why the job offer is not in Spanish ;)

We all do full development cycles from coding and testing to releasing and monitoring, QA and even setup the microservices configuration, so you must not be scared about configuring Dockerfiles or Travis ymls. Forget about "coding your stuff and somebody else will release it". We each push code multiple times per day and aim to have soon continuous delivery and blue/green deploys, but you will see we also already have a nice infrastructure with tools to ease your day to day.

You will be mentored for the first month(s), depending on the needs. One of the core goals is to share and spread the knowledge among all tech, so we not only encourage to do pairing (and TDD if you fancy it), but we're also starting to do inter-team pairing to get fresher points of view and advices, and of course to avoid knowledge silos.

Eventually most engineers will do on-call, but don't worry as we will train you when the time is right and help you so everything will be as smooth and easy as possible. It is a rotating shift (one week long), so the more people the less frequently it will be, and of course paid separately from your base salary.

We are a remote-friendly company (sadly not remote-first yet), so we encourage you to work remotely once per week if you want. You choose the day, but we try to spread so always there's somebody not in the office and we force to do online meetings, keep team diaries and communicate as much as possible. The position is initially for Madrid office, but could be negotiated.

As for the extras, we have fresh food & coffee, english lessons on tuesdays as mentioned earlier, and whenever our beloved teacher is available, also a weekly office yoga class on thursdays. We're trying to have either weekly or by-weekly internal workshops, although depends on availability of the designated speaker. There is also a monthly budget for books, conferences and/or internal training.

We're few engineers but growing at a slow but steady pace, at a young company but already with paying clients, and in general we're on that startup phase where not all is yet defined so anybody can help shape things. We will probably trash or evolve some pieces, iterate dozens of times on others, but we also have a core stable and robust rendering pipeline with scalability challenges.

If some or all of this looks interesting to you, drop me an email (kartones at themotion dot com), a Linkedin message or a Twitter PM (I've got them open so no need of following) and let's talk.

Previous entries