Subdomain redirects to main domain - Apache

Posted December 14, 2020 1.8k views

I’m having a problem with my subdomain. First, I use apache and my main domain is which uses WordPress. And now i’m trying to create a subdomain that will host a nodejs server in another port (3000).

I’ve created a A record via Digital Ocean networking panel. I’m looking for

Added new virtual host on 000-default.conf and this is my actual file:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted

        ErrorLog /var/www/html/error.log
        CustomLog /var/www/html/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

<VirtualHost *:80>

    DocumentRoot /var/www/html/quickie
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/html/quickie/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all

    ErrorLog /var/www/html/error-quickie.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/www/html/access-quickie.log combined
    # sub:
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass /
    ProxyPassReverse /

what intrigues me the most is when i use curl to my subdomain it responds with the html code i’m looking for. Meaning that nodejs is running and working.

What do I need to change more so that the subdomains works?

thanks for you help!

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.

Submit an Answer
2 answers

Hi @ivobastospereir,

First I’ll recommend separating your Apache configurations for each domain into separate virtual host files. If you are not sure how to do this, check this out

The second thing I’m seeing is that you are trying to reach I tried to open it up however was unable to. Maybe you’ll need to allow connections on port 3000. Another thing would be instead of using, you can try using localhost:3000 or and not the main domain.


by Lisa Tagliaferri
This tutorial will guide you through setting up multiple domains and websites using Apache virtual hosts on an Ubuntu 18.04 server. During this process, you’ll learn how to serve different content to different visitors depending on which domains they are requesting.
  • Hi @KFSys, tried to change to your suggestions, but none of them work. I want to redirect to port 3000, but it seems there is something always redirecting me to main domain. Already looked at .htaccess, but the problem doesn’t seem to be from there.

Can you confirm if created separate configuration files for your websites or are they still in the same file? Can you please separate them just so that it’s more clear going forward?

Additionally, I did understand you want to redirect
to port 3000 but from your last comment it seems like you want to redirect to https// rather than can you confirm to where you want to redirect the subdomain?

  • Oh, I just opened the subdomain, and I can see there is some content working there. Did you manage to solve the configuration issue?

    If so, can you confirm what it was so that if other people find it, they can see the solution?