Why isn't my apache httpd server serving content from my VirtualHost - apache

I have an apache httpd server running on a linux server. The server's fqdn is www.example.com, but I have a dns alias of www.example2.com for the same server.
When I access the server using my browser and use http://www.example.com it serves the correct content, but if I use http://www.example2.com, I get the default content from my /var/www/html folder not the content from the /var/www/html2 folder.
A stripped-down copy of my httpd.conf file follows:
ServerName www.example.com:80
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
CustomLog "logs/access_log" combined
ErrorLog "logs/error_log"
LogLevel warn
<VirtualHost www.example2.com:80>
ServerName www.example2.com:80
DocumentRoot /var/www/html2
CustomLog "logs/access_log2" combined
ErrorLog "logs/error_log2"
<Directory "/var/www/html2">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName www.example2.com
DocumentRoot /var/www/html2
CustomLog "logs/access_log2" combined
ErrorLog "logs/error_log2"
<Directory "/var/www/html2">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
The VirtualHost tag is for IP based filtering, to filter by host\server name use the ServerName directive.

Related

Set a default Virtual Host in Apache using Debian 10

I have a little problem.
I have a VPS configured with Apache, I have 2 VH, one is mydomain.com and other is subdomain.mydomain.com
Problem is that whenever I type the VPS IP in the browser, it goes to the subdomain. Is there a way to default this to the main domain?
I've created a folder called sites-enabled which contains both configuration files, they look something like this.
example.net.conf:
<VirtualHost *:80>
ServerName example.net
ServerAlias www.example.net
DocumentRoot /var/www/example.net
<Directory /var/www/example.net>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
admin.example.net.conf:
<VirtualHost *:80>
ServerName admin.example.net
DocumentRoot /var/www/admin.example.net
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/admin.example.net.log
CustomLog ${APACHE_LOG_DIR}/admin.example.net.log combined
</VirtualHost>
How can I set the first one to be the default?
place the below code in the 000-default.conf file
<VirtualHost *:80>
DocumentRoot /var/www/example.net
<Directory /var/www/example.net>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

you don't have permission to access / on this server. apache 2.4

I'm having the problem
you don't have permission to access / on this server. apache 2.4
while accessing my local web site. I already googled a lot and read a lot of posts here in StackOverflow and everything seems to be correct.
This is my apache version:
Server version: Apache/2.4.27 (Unix)
Attached my httpd.conf file.
Here is my httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost.smatchme.com
DocumentRoot "/Users/samuelrabini/Project/SmatchMe/smatchme.web"
ServerName localhost.smatchme.com
<Directory /Users/samuelrabini/Project/SmatchMe/smatchme.web>
Require all granted
Options Includes FollowSymLinks
AllowOverride All
</Directory>
DirectoryIndex index.php
ErrorLog "/private/var/log/apache2/localhost.smatchme.com-error_log"
CustomLog "/private/var/log/apache2/localhost.smatchme.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost.piuproduct.com
DocumentRoot "/Library/WebServer/Documents/piuproduct/public"
ServerName localhost.piuproduct.com
<Directory /Library/WebServer/Documents/piuproduct>
Require all granted
Options Includes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog "/private/var/log/apache2/localhost.piuproduct.com-error_log"
CustomLog "/private/var/log/apache2/localhost.piuproduct.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost.b2b.com
DocumentRoot "/Library/WebServer/Documents/b2b.tony"
ServerName localhost.b2b.com
<Directory /Library/WebServer/Documents/b2b.tony>
AllowOverride All
Require all granted
</Directory>
ErrorLog "/private/var/log/apache2/localhost.b2b.com-error_log"
CustomLog "/private/var/log/apache2/localhost.b2b.com-access_log" common
</VirtualHost>
Can anyone help me understand what I'm doing wrong?
I'm trying to access my site via http://localhost.b2b.com/
And I added in the /etc/hosts the entry:
127.0.0.1 localhost.b2b.com
thanks in advance
Samuel

403 Forbidden vhost Ubuntu

Trying to setup my webserver and allow .htaccess in all www directories. When accessing sub.domain.com on my laptop (with host files adjusted), returns a 403 Forbidden. "You don't have permission to access / on this server."
It feels like the .htaccess file is not allowed, and therefore throws the 403. But as per my understanding the settings are correct isn't? Am I overlooking something?
apache2.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
AllowOverride All
</Directory>
domain.com.conf
<VirtualHost *:80>
ServerName domain.com
ServerAlias sub.domain.com
ServerAdmin webmaster#domain.com
DocumentRoot /var/www/domain.com/public_html/support/current
<Directory "/var/www/domain.com/public_html/support/current">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName domain.com
ServerAlias .domain.com
ServerAdmin webmaster#domain.com
DocumentRoot /var/www/domain.com/public_html/support/current
<Directory "/var/www/domain.com/public_html/support/current">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Either /var/www/domain.com/public_html/support/current doesn't exist, or its rights are not correct for user Apache runs on. Check the User and Group settings in the main Apache config to find out what they are.
You might also want to check the error log to get additional clues.

Subdomain answer to specific folder in Apache

I want to configure an Apache vhost. Practically Basically I want by typing the address files.yyyyyy.ltd answer me the folder destination /var/www/html/alpha/files
This is apache configuration:
<VirtualHost *:80>
DocumentRoot /var/www/html/alpha/files
ServerName files.yyyyyy.ltd
ServerAlias files.yyyyyy.ltd
<Directory /var/www/html/alpha/files >
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
# Other directives here
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
DNS configuration:
yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
www IN CNAME yyyyyy.ltd.
yyyyyy.ltd. IN CNAME files.yyyyyy.ltd.
What is wrong? Do you recommend some other method to achieve the same result?
Thk for help
DNS configuration
you need to change
yyyyyy.ltd. IN CNAME files.yyyyyy.ltd.
to
files IN CNAME yyyyyy.ltd.
you can also set all as A record like
yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
www.yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
files.yyyyyy.ltd. IN A XXX.XXX.XXX.XXX
What i would do to have a faster name resolution.
Apache configuration
Your Apache configuration is correct, but some stuffs are useless:
<VirtualHost *:80>
DocumentRoot /var/www/html/alpha/files
ServerName files.yyyyyy.ltd
<Directory /var/www/html/alpha/files >
Options Indexes FollowSymLinks MultiViews
AllowOverride all
</Directory>
# Other directives here
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
AllowOverride all is there to allow .htaccess, if you don't want .htaccess files, you can remove this command from your configuration.

Apache vhost not working for subdomains

I have this configuration but both url app.test.com & stage.test.com
redirect to same code/deployment
<VirtualHost *:80>
ServerName app.test.com
DocumentRoot /var/www/html/Test-Prod/web
<Directory "/var/www/html/Test-Prod/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-prod__error_log
CustomLog logs/test-prod_access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName stage.test.com
DocumentRoot /var/www/html/Test/web
<Directory "/var/www/html/Test/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-website_error_log
CustomLog logs/test-website_access_log common
</VirtualHost>
The usual error for this is leaving out the NameVirtualHost directive if you're still using httpd 2.2
Add the following in your config file and it'll probably work
NameVirtualHost *.80
You might want to read the documentation for Named-based Virtual Host Support with httpd 2.2.
NameVirtualHost *.80
<VirtualHost localhost:80>
ServerName color
ServerAlias localhost
ServerPath "C:/wamp/www/subwww/color"
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www/subwww/color">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
in above code, subdomain name is color
and the url is http://color.localhost/
if the operating system is windows then add "127.0.0.1 color.localhost" in "C:/windows/system32/dirvers/etc/hosts" with notepad run as administration