How can i point subdomain to ip:port?

Hello, how can i point several subdomains to ip:port, for example -> 22.333.33.222:3000 -> 22.333.33.222:3001

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.

Site Moderator
Site Moderator badge
May 11, 2020
Accepted Answer

Hi @klapovsciuk,

You can redirect your domain to a certain port. This depends on the WebService you are using -Nginx/Apache. If you are using Nginx, you’ll need to do add a server block to your Nginx’s website config. This can be achieved by using the bellow

location /{

Having said that, you’ll need to add it to your subdomain’s Nginx server block/config. If you are unsure how you can do that, I’ll recommend checking out he following article:

If you are using Apache, you have two options, the first one is to add a redirection rule in your website’s .htaccess and the second one would be to do it directly in the Apache’s Vhost file. I like using the first option. In your .htaccess file, you can add the following rule

RewriteEngine on

# redirect to 3000 if current port is not 3000 and "some-prefix/" is matched
RewriteRule ^/(.*[^/])/?$$1/ [R=301,L]

If you want to use Apache’s Vhost file, I’ll recommend going through the following tutorial :

Regards, KDSys

Bobby Iliev
Site Moderator
Site Moderator badge
May 11, 2020

Hi there @klapovsciuk,

What you can do is:

  • Set up your DNS so that your subdomain names point to the server IP address: -> 22.333.33.222 -> 22.333.33.222
  • Then on the server itself set up a reverse proxy with Nginx for example to proxy the traffic for your domains to the respective ports accordingly:

Hope that this helps! Regards, Bobby

Try DigitalOcean for free

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

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

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

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
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