rioforce
By:
rioforce

How to point a port to a subdomain?

October 10, 2015 2.6k views
DNS Miscellaneous Ubuntu

I'm running ubuntu on a digitalocean server, and I have a web app rutting on port 3001. Basically, how my site is currently setup, I have to go to mydomain.com:3001 to reach the web app. I'd like to make it use app.mydomain.com instead. Is there any possible solution for this? I'm new to hosting and subdomains.

Thank you in advance! :)

4 comments
  • What type of web server are you using with your app?
    You may want to investigate virtual hosts, but let us know, and we can give you more specific advice.
    Thanks

  • @BrookDO I'm using Digital Ocean for my webserver. I have been Googling, but haven't been finding anything, so this "virtual host" you speak of may work (but I don't know what it is unfortunately). Maybe you could point me in the right direction?

    Thanks.

  • @BrookDO After a bit more searching, I figured out about virtual hosts.

    https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

    I made a CNAME in the DNS so that I have app.mydomain.com, and setup my virtual host file like this:

    <VirtualHost *:80>
        ServerAdmin email@email.com
    
        ServerName app.mydomain.com
        ServerAlias www.app.mydomain.com
        DocumentRoot /root/app/web
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    As you can see, the document root isn't under /var/www/mydomain/public_html like normal sites are. I always get a 403 Forbidden when I attempt to access the subdomain. I even tried putting a simlink in the /var/www/mydomain/public_html folder, directing to my app in /root/app/web, but I still get a forbidden error. However, the url "mydomain.com:3001" still goes to the app.

    by Justin Ellingwood
    The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 14.04 VPS.
  • Hi,

    Are the permissions correct for the /root/app/web folder?

    sudo chown -R $USER:$USER /root/app/web/
    sudo chown -R $USER:$USER /root/app/web
    sudo chmod -R 755 /root/app/
    

    Also, in this case, I would remove the "www" from the line

     ServerAlias www.app.mydomain.com
    

    as the alias will still be app.mydomain.com

    Also, did the step that included this command

    sudo a2ensite
    

    work? And when you restarted Apache, did you see any errors?

Be the first one to answer this question.