Question

Setting up a sub-domain to point to a flask application on same droplet (with uwsgi and nginx on Ubuntu 15.10)

I have a domain called abc.com which points to a static html page, in /var/www/abc.com/public_html.

I want to host a Flask application on same droplet (different port maybe?), which is accessible using a subdomain demo.abc.com.

I followed instructions here, and here, but they seem not to be working for me right now.

Here is a how my Zone file looks like currently -

$ORIGIN abc.com.
$TTL 1800
abc.com. IN SOA ns1.digitalocean.com. hostmaster.abc.com. 1451918078 10800 3600 604800 1800
abc.com. 1800 IN NS ns1.digitalocean.com.
abc.com. 1800 IN NS ns2.digitalocean.com.
abc.com. 1800 IN NS ns3.digitalocean.com.
abc.com. 1800 IN A 111.222.333.44
*.abc.com. 1800 IN CNAME abc.com.

I have created an app.py in /var/www/demo.abc.com/ which has

from flask import Flask
application = Flask(__name__)

@application.route("/")
def hello():
    return 'Hello World!'

if __name__ == "__main__":
    application.run(host='0.0.0.0')

I have 2 files in /etc/nginx/sites-available abc.com demo.abc.com

Here is what demo.abc.com looks like:

server {
    listen 80;
    server_tokens off;
    server_name demo.abc.com;

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

     location /static {
         alias /var/www/demo.abc.com/static;
     }

     ## Only requests to our Host are allowed
     if ($host !~ ^(demo.abc.com.com|www.demo.abc.com)$ ) {
        return 444;
     }
}

Here is what /etc/uwsgi/apps-available/demo.abc.com.ini looks like

[uwsgi]
vhost = true
socket = /tmp/demo.sock
venv = /var/www/demo.abc.com/.env
chdir = /var/www/demo.abc.com
module = app
callable = application

master = true
processes = 5

chmod-socket = 660
vacuum = true

die-on-term = true

abc.com works fine, while demo.abc.com is not running. I don’t get any error while starting service nginx and uwsgi. I am however beginner in both of them. Please guide me on what I am doing wrong


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

When finding problems en debugging them its always usefull to use logs to see what is going on. Define your logs and check what nginx tells you once you access the website :

        error_log /var/log/demo.abc_error.log;
        access_log /var/log/demo.abc_access.log combined;