logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Trouble with virtual hosts going to the wrong document root
Author
wesman00



Joined: 10 Jan 2020
Posts: 9
Location: United States

PostPosted: Sun 05 Jun '22 21:29    Post subject: Trouble with virtual hosts going to the wrong document root Reply with quote

I installed pterodactyl on my server to streamline dedicated game server creation and during the installation, I set the virtual host to pterodactyl.mydomain.com. When going to this subdomain everything works including SSL so that's amazing. When I go to mydomain.com expecting to see the default Apache "It works" page, it instead gives me an SSL warning saying that the certificate doesn't match and I click proceed and it sends me to the login page for pterodactyl as if I had gone to pterodactyl.mydomain.com instead. The same happens when I type my public IP address (or local when on the same network) into my browser and I'm sent to the pterodactyl login page after clicking proceed on the SSL warning. However, when I go to www.mydomain.com I see the "it works" page. I own another domain pointed at the same server and IP address and when I go to domain2.com it sends me to the pterodactyl login page when I was expecting again to be sent to the default "it works" page since I don't have a virtual host set up yet for the second domain.

Inside my /etc/apache2/sites-available/ directory I have files called 000-default.conf default-ssl.conf pterodactyl.conf and mydomain.conf and I don't have one for my other domain yet but these are all enabled in sites-enabled.

Inside 000-default.conf:
Code:
<VirtualHost *:80>
        ServerAdmin me@mydomain.com
        DocumentRoot /var/www/mydomain
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


Inside pterodactyl.conf:
Code:
<VirtualHost *:80>
  ServerName pterodactyl.mydomain.com

  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>

<VirtualHost *:443>
  ServerName pterodactyl.mydomain.com
  DocumentRoot "/var/www/pterodactyl/public"

  AllowEncodedSlashes On

  php_value upload_max_filesize 100M
  php_value post_max_size 100M

  <Directory "/var/www/pterodactyl/public">
    Require all granted
    AllowOverride all
  </Directory>

  SSLEngine on
[ssl stuff is here but this post is getting long]
</VirtualHost>


Inside mydomain.conf:
Code:
<VirtualHost *:80>
    ServerAdmin me@mydomain.com
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/mydomain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


I copied the "it works" page into /var/www/mydomain so I think I should see it when I go to mydomain.com. My goal right now is to have mydomain.com and www.mydomain.com point to documents hosted in /var/www/mydomain and to have mydomain2 point to documents I will eventually create in /var/www/mydomain2. I also want to make it so if a client accesses my site from my public IP address they are met with the default apache page. I don't plan on hosting anything there besides the "it works" page. What am I doing wrong?
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 348
Location: UK

PostPosted: Mon 06 Jun '22 21:00    Post subject: Reply with quote

Your post shows a non-secure and secure configuration for pterodactyl.mydomain.com, whilst all other sites are non-secure. So are your problem client requests secure or non-secure? If secure, then they'll be processed by the only secure configuration you've got, which is for pterodactyl.mydomain.com. Hence the certificate challenge if the client is using a different site hostname, in which case believe you'll need some additional secure sites configuring.

Check the virtual host documentation https://httpd.apache.org/docs/current/mod/core.html#virtualhost to understand how Apache handles server names, server aliases and default hosts, and use the command "httpd -t -D DUMP_VHOSTS" to show the virtual host configuration apache is actually using.
Back to top


Reply to topic   Topic: Trouble with virtual hosts going to the wrong document root View previous topic :: View next topic
Post new topic   Forum Index -> Apache