0

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?

1
  • 1
    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.
    – YonzLeon
    Commented Mar 29, 2023 at 2:23

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .