Score:0

Apache2 subdomain not found after addition

ng flag

Here is a situation

I have example.com domain pointed to my server where Apache2 runs. Currently I have two confs (one for HTTP and one for HTTPS) that accepts example.com requests and shows page thats stored in folder /var/ww/html/example

HTTP conf (example.com.conf)

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/example
ServerName example.com
ServerAlias www.example.com
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log common
Redirect permanent / https://example.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

HTTPS conf is basic conf generated by certbot with no changes

But what I want to achieve now is to have subdomain demo.example.com which simply points to root html folder /var/www/html/ (so if I type demo.example.com/some-folder is shows content of this folder)

So I´ve tried this

HTTP conf (exampledemo.com.conf)

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName demo.example.com
ServerAlias www.demo.example.com
ErrorLog logs/demo.example.com-error_log
CustomLog logs/demo.example.com-access_log common
Redirect permanent / https://demo.example.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =demo.example.com [OR]
RewriteCond %{SERVER_NAME} =www.demo.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

HTTPS conf is basic conf generated by certbot with no changes

But when I added site and restarted apache, I am getting not found page that I have on my server as fallback so this configuration probably does not match my conf

HTTP conf (000-default.conf)

<VirtualHost *:80>
DocumentRoot /var/www/html/not-found
</VirtualHost>

Can anyone please tell me what I am doing wrong?

YonzLeon avatar
de flag
first thing you need to make sure your configfile loaded in Apache by run `apache2ctl -S` if the conf not loaded its mean you place the config file inside wrong apache dir.
Score:0
kz flag

It seems that your configuration is conflicting with the default configuration 000-default.conf which is serving the "not found" page.

  1. Disable the default configuration:
sudo a2dissite 000-default.conf
  1. Check the DNS settings:
nslookup demo.example.com
  1. Check the Apache configuration:

Make sure that your new configuration file exampledemo.com.conf is in the correct directory /etc/apache2/sites-available/ and that it has the correct permissions.

You can also check the Apache error log for any errors related to the configuration. The error log is usually located at /var/log/apache2/error.log.

Then restart Apache:

sudo systemctl restart apache2
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.