I am trying to direct web traffic for our domain to a Vhost site and our internal web site to separate directory that is only accessible within our private network,i.e 192.168.x.x.
I have modified Vhost configuration on Apache to include a name-based Vhost for the external website and a IP Vhost for the Intranet. No far I have had no luck, Apache does not like it.
Here is my modified Vhost config file.
NameVirtualHost *:80
<Directory "/home/webs">
Options +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot /home/webs/foo
ServerName www.foo.com
ServerAlias foo.com
LogLevel warn
ErrorLog /home/webs/foo/error.log
CustomLog /home/webs/foo/logs/access.log combined
</VirtualHost>
NameVirtualHost 192.168.0.*:80
<Directory "/home/webs/OffCat">
Options +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost 192.168.0.*:80>
DocumentRoot /home/webs/OffCat
ServerName 192.168.0.15/OffCat
LogLevel warn
ErrorLog /home/webs/OffCat/logs/error.log
CustomLog /home/webs/OffCat/logs/access.log combined
</VirtualHost>
I would appreciate any help.
Thanks,
Tony Cripps
Related
I am trying to have two separate sites with Apache virtual hosts on a test server. I am going to access the sites with the ip address of the instance (for example, http://167.275.122.215). When I enable the following configuration, I would be able to load the first site with just the ip address correctly (with http://167.275.122.215), but not http://167.275.122.215/exp. I get a 404 error when I point to that address. What am I doing wrong here?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
Alias /exp /usr/share/wordpress
DocumentRoot /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
In fact, my need is to be able to access the exp (experimental) site through the same ip while the main site is still available (from the original ip address). I tried giving a different port to the experimental site too (like below), but that still gave me a site can't be reached error.
<VirtualHost *:90>
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
For port based multiple sites, listing the default port as the second site resolved the issue:
LISTEN 90
<VirtualHost *:90>
DocumentRoot /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
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.
I have upgraded my Apache to 2.4 and all my virtual hosts configs stopped to work. Most of the were configured like following:
<VirtualHost *:80>
ServerAdmin MYEMAIL
DocumentRoot "MYPATH"
ServerName MYNAME
ErrorLog "logs/garmonia3.log"
CustomLog "logs/garmonia3.log" common
DirectoryIndex page.php
</VirtualHost>
First sites became forbidden. I tried to find some workarounds and found them like
<VirtualHost *:80>
ServerAdmin MYEMAIL
DocumentRoot "MYPATH"
ServerName MYNAME
ErrorLog "logs/garmonia3.log"
CustomLog "logs/garmonia3.log" common
DirectoryIndex page.php
<Directory "MYDIR">
Options FollowSymLinks MultiViews
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
but these are probably obsolete, since Apache is swearing on both Order and Allow directory.
So how to enable?
everybody.
I have a Cent OS 6.6 server with Apache + mod_php site (site1.local). I need to configure second site (site2.local) with php_cgi. So, I created a user, gave him permissions on www-folder, configured site1 as mod_php, created a phpinfo.php. Also, I installed php-cgi,and try to configure virtual hosts, works only first site, on the second site is error:
the requested url /cgi-bin/phpinfo.php was not found onthis server.
That's my configs:
cat /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster#site1.local
DocumentRoot /var/www/wwwmaster/site1.local
ServerName site1.local
ServerAlias www.site1.local
ErrorLog logs/site1.local-error_log
CustomLog logs/site1.local-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.local
DocumentRoot /var/www/wwwmaster/site2.local
ServerName site2.local
ServerAlias www.site2.local
ScriptAlias /cgi_bin/ /usr/bin/php-cgi/
Action php-cgi /cgi-bin
AddHandler php-cgi php
<Directory /usr/bin/php-cgi>
Allow from all
</Directory>
<Directory "/var/www/wwwmaster/site2.local/">
<FilesMatch "\.php">
SetHandler php-cgi
</FilesMatch>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
ErrorLog logs/site2.local-error_log
CustomLog logs/site2.local-access_log common
</VirtualHost>
What I've done wrong and how can I fix that?
You only have to uncomment the line that says NameVirtualServer *:80 in your apache config file.
If you want virtual server for more than one port, simply put as many NameVirtualServer *:[port number] in the apache config file as you need.
I have defined two VirtualHosts on Apache, and the problem is, one of them overrides the other one. i.e. when I try to reach the second address, the first one shows up.
Here is my first config:
ServerName www.example1.com
DocumentRoot /server/sites/example1
<VirtualHost *:80>
ServerAdmin admin#example1.com
DocumentRoot /server/sites/example1
ServerAlias example1.com
<Directory /server/sites/example1/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And the second:
ServerName www.example2.tv
DocumentRoot /server/sites/tv/public/
<VirtualHost *:80>
ServerAdmin admin#example2.tv
DocumentRoot /server/sites/tv/public
<Directory /srver/sites/tv/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
When I load www.example2.tv, it still shows www.example1.com content.
example1 is written in PHP and example2 is Ruby on Rails.
You need to have the ServerName directive inside the VirtualHost configuration i.e.:
<VirtualHost *:80>
ServerName www.example2.tv
ServerAdmin admin#example2.tv
DocumentRoot /server/sites/tv/public
<Directory /server/sites/tv/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
You can examine your configured VirtualHosts using apachectl -S - this will print a list of all the configured VirtualHosts and their corresponding config files