Question

How to configure Droplet to run python application on custom domain

I’m new to this. A friend and I have been trying to set up a MUD game we’re building. I’ve managed to get it installed in my Droplet, and I’ve purchased a custom domain for the game to be played from. My problem is in configuring my droplet in a way that it will a) run the app (evennia start from the project’s main directory) and b) allow for connection to the app through my custom domain. Any help at all would be greatly appreciated.


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.

KFSys
Site Moderator
Site Moderator badge
April 9, 2024
Accepted Answer

Heya @jaycb3,

First, you’ll need to configure Nginx and make it work as a reverse proxy.

Step 1: Install Nginx

If you haven’t already installed Nginx, you can do so using your system’s package manager. For most Linux distributions, the command is:

  • On Ubuntu/Debian:
sudo apt update
sudo apt install nginx
  • On CentOS/RHEL:
sudo yum install epel-release
sudo yum install nginx

Step 2: Configure Nginx as a Reverse Proxy

  1. Create a new configuration file for your domain in the /etc/nginx/sites-available/ directory (you can name the file after your domain for clarity, like doomain.com.conf):
sudo nano /etc/nginx/sites-available/doomain.com.conf

where doomain.com would be the real domain that you have purchased.

sudo nano /etc/nginx/sites-available/doomain.com.conf

Add the following configuration to the file. This configuration tells Nginx to listen on the default HTTP port (80) and proxy the requests to your application running on localhost, port 3000:

server {
    listen 80;
    server_name example.com; # Replace with your domain name or IP address

    location / {
        proxy_pass http://localhost:3000; # Proxy pass to the app on port 3000
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Since I do not know on which port your application runs, I’ve set it to 3000 however you can set it to any port you wish.

Replace example.com with your domain name or IP address.

Symlink this file to the /etc/nginx/sites-enabled/ directory to enable it:

sudo ln -s /etc/nginx/sites-available/doomain.com.conf /etc/nginx/sites-enabled/

Step 3: Test and Restart Nginx

  1. Test the Nginx configuration for syntax errors:
sudo nginx -t
  1. If you get a message that says the syntax is OK, restart Nginx to apply the changes:
sudo systemctl restart nginx

Step 4: Adjust Firewall Settings (If Applicable)

If you have a firewall running, such as ufw, you need to allow HTTP traffic:

  • On Ubuntu/Debian:
sudo ufw allow 'Nginx Full'

Step 5: Access Your Application

You should now be able to access your application via your server’s domain name or IP address (on port 80) in a web browser.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.