Forum Moderators: phranque

Message Too Old, No Replies

Adding second website config to Apache

         

Larryfox

11:38 pm on Apr 8, 2022 (gmt 0)

Top Contributors Of The Month



My Apache2 local server is working fine for my website. I've added a test.conf to sites-available and added it to my hosts file so I can do some experimentation without messing with my production website. The problem is that when I try to go to it in my web browser, I get a Not Found. This is on a Linux system, and yes, I did restart apache after I added test.conf. There's nothing in either the error log or the access log. My entry from sites-enabled follows:
<VirtualHost *:80>
ServerAdmin webmaster@test
ServerName test
ServerAlias test
DocumentRoot /var/www/test/public_html
<Directory />
AllowOverride All
</Directory>
<Directory /var/www/test/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
ErrorLog /var/log/apache2/test-error.log
LogLevel error
CustomLog /var/log/apache2/test-access.log combined
</VirtualHost>


I'd appreciate some help on this.

Larryfox

11:43 pm on Apr 8, 2022 (gmt 0)

Top Contributors Of The Month



Thinking more about my issue, I wonder if test is a reserved word.

Larryfox

4:48 pm on Apr 9, 2022 (gmt 0)

Top Contributors Of The Month



I did some testing. If I enter 127.0.0.1/test/public_html, the new test website appears in the web browser. This tells me the problem isn't in the hosts file. If I enter http://test/public_html in the web browser, I get a Not Found. This tells me that the the problem is with Apache.



[edited by: not2easy at 4:56 pm (utc) on Apr 9, 2022]
[edit reason] delinked for readability [/edit]

not2easy

5:11 pm on Apr 9, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Hi Larryfox and welcome to WebmasterWorld [webmasterworld.com]

Sorry I'm not much help for this, there are folks here who can help, but outdoors and warmer weather can make weekends slower for responses. The /test/ directory is above the public_html directory so /test/ is just the account name. I would not expect to view a page using that path. But I don't set up apache, I'm not the one who can help.

I keep folders of my sites and view/edit them in my browser or in my editor without setting up apache. Of course that means that .js works fine, but php does not, and external resources aren't available. Be patient, someone will pass through who can assist better.

w3dk

9:14 pm on Apr 9, 2022 (gmt 0)

10+ Year Member Top Contributors Of The Month



I've added a test.conf to sites-available


Depending on your Apache distro you would normally need to make a symlink from "sites-enabled" to the corresponding file in "sites-available". (Or include the conf file directly in "sites-enabled".) So, your conf file may not be doing anything.

If I enter 127.0.0.1/test/public_html, the new test website appears in the web browser.


It looks like you have another VirtualHost (or perhaps even the main server config) that is catching the request in which the DocumentRoot is set to "/var/www". (This may be due to the above conf file not being included.)

If there is no specific vHost defined to catch the request then the "default" (first defined) vHost (or main server config) will catch the request.

The problem is that when I try to go to it in my web browser, I get a Not Found.


If you are getting a 404 Not Found response then it is resolving to somewhere. What exactly are you requesting initially? In your later post you mention "http://test/public_html" - but that would generally be expected to result in a 404.


<Directory />
AllowOverride All
</Directory>


You shouldn't be allowing ".htaccess" overrides for the entire system. You are already setting this for the specific directory - which should be all that's required (if indeed you are using ".htaccess" files).

Larryfox

10:30 pm on Apr 9, 2022 (gmt 0)

Top Contributors Of The Month



I got it fixed by combining the two files. My fixed file follows:
<Directory />
AllowOverride None
</Directory>

<VirtualHost *:80>
ServerAdmin webmaster@test
ServerName www.project1.test
DocumentRoot /var/www/foxclone/public_html
<Directory /var/www/public_html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/project1-error.log
LogLevel error
CustomLog /var/log/apache2/project1-access.log combined
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@test
ServerName www.project2.test
DocumentRoot /var/www/test/public_html
<Directory /var/www/public_html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/project2-error.log
LogLevel error
CustomLog /var/log/apache2/project2-access.log combined
</VirtualHost>

w3dk

11:16 pm on Apr 9, 2022 (gmt 0)

10+ Year Member Top Contributors Of The Month



Your <Directory> sections don't match the corresponding DocumentRoot directive?

phranque

12:45 am on Apr 10, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Larryfox!

If there is no specific vHost defined to catch the request then the "default" (first defined) vHost (or main server config) will catch the request.

i believe this means the following url would have also resolved:
http://test/test/public_html

it also means you should have found clues for this problem in the log files for the default server config.