Issue
My goal
Running 2 name virtual host with 1 IP. For example, front1.httpd.example.com
and front2.httpd.example.com
are accesible on 1 server's 1 httpd (parent) process(I want to listen on port 80 in both front1 and front2).
Environment
httpd 2.4 and Ubuntu 11(32bit)
What I did
I added to two virtual host on httpd.conf according to the latest offical document Name-based Virtual Host Support.
And also I update my server /etc/hosts and client hosts like the following.
server's hosts(220.xxx.xxx.xxx is some actual IP)
127.0.0.1 front1.httpd.example.com front2.httpd.example.com localhost
220.xxx.xxx.xxx front1.httpd.example.com
222.xxx.xxx.xxx front2.httpd.example.com
client's hosts
220.xxx.xxx.xxx front1.httpd.example.com
220.xxx.xxx.xxx front2.httpd.example.com
In addition, my hostname is front1.httpd.example.com
(Note: I also tried to add NameVirtualHost *:80
before the VirtualHost sections, but it just returns additional message "NameVirtualHost has no effect...")
Results
When I access to front1.httpd.example.com/index.html
, htdocs/xxxx/index.html
is returned. This is what I expected, but when I access to front2.httpd.example.com/index.html
, also htdocs/xxxx/index.html
is returned in spite of I intend to show htdocs/yyyy/index.html
.
(in browser console message, front2.httpd.example.com/index.html
is found and then 302 redirect to front1.httpd.example.com/index.html
)
Virtual host will return the first Virtual host value if there is no matching result to access. So, I also tried to change the oreder of the virtual host like the following:
First try:
<VirtualHost *:80>
DocumentRoot "/opt/APACHE/httpd/htdocs/xxxx"
ServerName front1.httpd.example.com
ServerAlias front1.httpd.example.com
ErrorLog "logs/dummy-host1.example.com-error_log"
<Directory "/opt/APACHE/httpd/htdocs/xxxx">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/opt/APACHE/httpd/htdocs/yyyy"
ServerName front2.httpd.example.com
ServerAlias front2.httpd.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
<Directory "/opt/APACHE/httpd/htdocs/yyyy">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
and second try:
<VirtualHost *:80>
DocumentRoot "/opt/APACHE/httpd/htdocs/yyyy"
ServerName front2.httpd.example.com
ServerAlias front2.httpd.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
<Directory "/opt/APACHE/httpd/htdocs/yyyy">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/opt/APACHE/httpd/htdocs/xxxx"
ServerName front1.httpd.example.com
ServerAlias front1.httpd.example.com
ErrorLog "logs/dummy-host1.example.com-error_log"
<Directory "/opt/APACHE/httpd/htdocs/xxxx">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
As a result, front2.httpd.example.com/index.html
returns htdocs/yyyy/index.html
, but front1.httpd.example.com/index.html
also returns htdocs/yyyy/index.html
. Therefore, I guess accessing request does not much any virtual host.
Refs and comments
I checked similar questions like this Virtual Host on CentOS5, but in my case I wrote hosts file on the both server and client, so DNS things are not for me, I think.
I had setup the httpd server for past a few years and also used VirtualHost
with old stuff NameVirtualHost
, but this time something I screwed up or I don't know.
Please provide me any ideas?
My httpd.conf
ServerRoot "/opt/APACHE/httpd"
Listen 80
<VirtualHost *:80>
DocumentRoot "/opt/APACHE/httpd/htdocs/xxxx"
ServerName front1.httpd.example.com
ServerAlias front1.httpd.example.com
ErrorLog "logs/dummy-host1.example.com-error_log"
<Directory "/opt/APACHE/httpd/htdocs/xxxx">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/opt/APACHE/httpd/htdocs/yyyy"
ServerName front2.httpd.example.com
ServerAlias front2.httpd.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
<Directory "/opt/APACHE/httpd/htdocs/yyyy">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
<IfModule unixd_module>
User ubuntu
Group ubuntu
</IfModule>
<Directory />
AllowOverride none
Require all denied
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/opt/APACHE/httpd/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/opt/APACHE/httpd/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Solution
I'm using OpenAM Web policy agent at this server instance.
As a result, just adding each FQDN to the FQDN virtual mapping on OpenAm agent profile reach the my goal.
Answered By - tkhm Answer Checked By - Terry (WPSolving Volunteer)