By webutek
I’ve tried adding a SRV record, but the form prevents setting the destination to @ (the base host).
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!
Accepted Answer
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.
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.