By kampta
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
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!
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;
Heya,
Your configuration appears mostly correct at a glance. However, let’s troubleshoot step by step:
DNS Settings:
demo.abc.com is correctly pointing to your DigitalOcean droplet’s IP address. This seems correct as per the zone file you provided, but you can double-check using ping demo.abc.com and see if it resolves to the correct IP.Nginx Configuration:
demo.abc.com is symlinked to the sites-enabled directory:sudo ln -s /etc/nginx/sites-available/demo.abc.com /etc/nginx/sites-enabled/
demo.abc.com.com in the server block (if condition). This seems like a typo. It should be demo.abc.com.uWSGI Configuration:
apps-enabled directory:sudo ln -s /etc/uwsgi/apps-available/demo.abc.com.ini /etc/uwsgi/apps-enabled/
www-data).cd /var/www/demo.abc.com/
source .env/bin/activate
python app.py
If it runs correctly, you should be able to access the Flask app at http://demo.abc.com:5000.
5. Logs:
demo.abc.com domain:sudo tail -f /var/log/nginx/error.log
Check uWSGI logs for any issues related to the Flask app:
sudo tail -f /var/log/uwsgi/app/demo.abc.com.log
sudo service nginx restart
sudo service uwsgi restart
ufw on Debian:sudo ufw allow http
sudo ufw allow https
Try the above steps one by one and see if you can pinpoint the issue. The log files, in particular, will be very helpful in diagnosing the problem.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.