Question

How do I set my domain to point to the VPS' IP address with also a port and path specified?

I’ve tried adding a SRV record, but the form prevents setting the destination to @ (the base host).


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.

@webutek

If you’re running an application that runs on a port other than port 80 or 443 (HTTP and HTTPS), and the application isn’t designed to run on those ports (i.e. most NodeJS apps, for example), then what you’d want to do is setup a proxy. This would essentially accept a request on port 80/443 and then proxy it to the port that your application is running on.

Most DNS providers, other than Amazon, CloudFlare, and potentially Google (not 100% on as I’ve not used their DNS in a while) won’t allow you to point anything other than you domain to root (i.e. @).

DigitalOcean falls in to that category as of this post (i.e. it’s not allowed).

Using a proxy (i.e. setting up NGINX as a proxy, for example), will allow you to setup a server block such as:

upstream myapp {
    server http://localhost:2623;
}

server
{
    listen                          80 default_server;
    listen                          [::]:80;
    server_name                     _;

    root                            /home/nginx/htdocs/public;

    location /
    {
        proxy_pass myapp;
        proxy_connect_timeout 59s;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers 16 32k;
        proxy_busy_buffers_size 128k;
        proxy_temp_file_write_size 64k;
        proxy_pass_header Set-Cookie;
        proxy_redirect off;
        proxy_set_header Accept-Encoding '';
        proxy_ignore_headers Cache-Control Expires;
        proxy_set_header Referer $http_referer;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_hide_header X-Powered-By;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_no_cache $http_pragma $http_authorization;
        proxy_cache_bypass $http_pragma $http_authorization;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
    }
}

What the above would do is take a request on Port 80, proxy it to the myapp backend block, which sets the ‘server’ to use – in this case, it’d be http://localhost:2623, which would be an application that is running on port 2623.

You can setup multiple upstream blocks to proxy to different applications and you can setup multiple location blocks to handle different paths.

For example, we could add:

upstream myapp2 {
    server http://localhost:2624;
}

Create a new location block that uses it at a path other than /:

location /newpath {
    proxy_pass myapp2;
}

Now when a request for /newpath is made, it’ll respond with the application running on 2624 as per the new upstream block we just set up.

That’s one way of doing it and keeping ports off the URL.

You can’t, your webserver determines that.

Try DigitalOcean for free

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

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel