nginx configuration to work with flask blueprints' subdomain

July 16, 2018 2.2k views
Nginx Python Python Frameworks Django Ubuntu 16.04

I looked everywhere for this but didn’t find any answer

I have an application, and I decided to run almost every blueprint in its own subdomain .. static ones. example:

  1. > admin interface

  2. > anything user related, login log out register ..etc

  3. > api

  4. and > normal app

now I know for a fact that my code works perfectly fine, because when I test it using:

  1. python

  2. flask run

  3. uwsgi –socket –protocol=http -w run:app

it worked just fine with the intended result

I am usingubuntu 16.04 if it matters. while testing, I set SERVER_NAME to but now since I want to to run in production I changed it to but it still not working

here are my files:


module = run:app
master = true
processes = 5
socket = myrpoject.sock
chmod-socket = 660
vacuum = true
die-on-term = true


server {
    listen 80;
    server_name MY_IP;
    location / {
        include uwsgi_params;
        uwsgi_pass unix:///home/gin/myproject/myproject.sock;
    location ^~ /static/ {
        include /etc/nginx/mime.types;
        root /home/gin/myproject/app/;


Description=uWSGI instance to serve myproject
ExecStart=/home/gin/myproject/venv/bin/uwsgi --ini uwsgi.ini --uid gin --gid www-data

and finally my digitalocean droplets without ns:

Type         Hostname                            Value                            TTL (seconds)
A           directs to MY_IP          80
A              directs to MY_IP          80
A                    directs to MY_IP          80
A                 directs to MY_IP          80
A                 directs to MY_IP     80

I tried setting www as CNAME but nothing really changed

Right now with these config:

  1. and both works, everything works as intended

  2. subdomains don’t work at all, they instead redirect to “welcome to nginx” page

1 Answer

If I understand correctly, you would like all subdomains to also be handled by your flask app?

If YES - I think you need to change your nginx config line to also listen for these subdomains:
server_name MY_IP;
server_name MY_IP *;

That’s a very well-written question!

  • Thank you :D
    I should have said that I did this already, but now for example points to too :(

    I gave up and used url-prefixes instead, so becomes

Have another answer? Share your knowledge.