• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero Blog

NameHero Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories

How To Point A SubDomain To A Non-Standard Port With SSL On cPanel

Ryan Gray

Published on: February 13, 2020

Categories: Website Development 4

Recently I needed to run a Ruby app on cPanel using a non-standard Apache port (i.e. http://mydomain.com:6000) but wanted to send live traffic to a subdomain with SSL (i.e. https://sub.mydomain.com).

After some research along with some trial and error I discovered a method that worked easily, therefore I wanted to share it to hopefully save you the time I spent on it!

Open The Custom Port In Firewall

To get started, you want to first verify that the port is open in your firewall, and you’re able to load it in your web browser (i.e. http://mydomain.com:6000 loads).

If you’re using a VPS or Cloud Dedicated from NameHero, we include ConfigServer Security & Firewall (CSF) in our images by default, so you’d want to open the port there:

Please note: This tutorial will not work on our Web Hosting or Reseller Hosting packages as it requires full root access.

Login to Web Host Manager as root user and click on ConfigServer Security & Firewall:

Click on Firewall Configuration:

Scroll down to TCP_IN and TCP_OUT and add your custom port (i.e. 6000):

Click change and restart the CSF service.

Install Mod Proxy In Easy Apache 4

To make this work, we need use Apache’s Mod Proxy to route the subdomain to the custom port. With cPanel’s Easy Apache 4, this can easily be installed, if it’s not already:

If you don’t see the green “Installed”, simply toggle the button and recompile Apache with it.

Setup Your SubDomain With SSL

In order to point the custom port to a subdomain with SSL, you’ll need to make sure it’s setup with an active SSL certificate.

Thankfully using cPanel’s Auto SSL module, this is 100% free as long as it’s enabled in Web Host Manager:

With this verified, you can create the subdomain in cPanel or Web Host Manager.

In my case, my root domain is hosted on a different server, therefore I’m going to create a cPanel account for the subdomain and point my A record using Cloudflare:

Once created, you may need to go back to Auto SSL in Web Host Manager and manually run the module to generate the SSL, or give it a few hours for the automation.

When you’re able to access your subdomain in your browser with SSL, you’ll ready to proceed (i.e. https://sub.domain.com).

Modify Apache Configuration

Finally, we need to modify Apache’s configuration file, so it knows how to properly route the subdomain to the custom port.

When you’re doing this with cPanel/WHM, it’s important to use their include files so an upgrade doesn’t remove your customization and you don’t break native configuration.

This can easily be done inside of Web Host Manager -> Apache Configuration -> Include Editor:

From here, you’re going to want to modify the Pre VirtualHost Include file with the following:

<VirtualHost *:80>
 ServerName sub.mydomain.com

ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass / http://mydomain.com:6000/
ProxyPassReverse / http://mydomain.com:6000/
<Location />
    Order allow,deny
    Allow from all
</Location>
</VirtualHost>

It should look something like this:

If you format this incorrectly, you may receive an error that it will not save, so that would need to be resolved before proceeding. cPanel has a ton of Documentation on this, which maybe beneficial.

Finally, you should run the following commands via SSH as root:

[[email protected] ~]# /scripts/rebuildhttpdconf
[[email protected] ~]# service httpd restart

As long as you followed the above instructions and completed them without errors, you should now be able to load your subdomain via SSL that points to your custom port (i.e. https://sub.mydomain.com). Please note you may need to flush your local DNS cache if the subdomain existed previously.

Please note: As a disclaimer, this is not an official cPanel method therefore we are unable to provide support for it. This should be used with full warning that you acknowledge the risks involved.

Feel free to let me know if you have any questions, I’ll try my very best to help!

Ryan Gray
Ryan Gray

Ryan Gray is the founder and CEO of NameHero, one of the fastest growing independent web hosts in the United States. Ryan has been working online since 1998 and has over two-decades experience in Internet Entrepreneurship.

Reader Interactions

Comments

  1. Eric says

    May 29, 2020 at 7:58 pm

    I’ve been struggling with trying to expose an app via subdomain through https?

    Reply
  2. Saulo says

    September 16, 2021 at 4:22 pm

    It’s not working for me. It’s reading the DocumentRoot of the cPanel account I created with the subdomain.

    Reply
    • Joshua says

      December 8, 2021 at 10:03 pm

      same, did you fix this issue?

      Reply
  3. Ryan Gray says

    December 9, 2021 at 11:27 am

    Try:

    < VirtualHost *:443 >
    ServerName sub.mydomain.com

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

Speed up your site: solving the WordPress slowdown

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • Website Performance
  • Web Hosting
  • Resellers
  • Website Development
  • Website Security
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Knowledgebase
  • Announcements
  • Affiliates
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 NameHero, LLC. All rights reserved.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA