apache - mod_proxy to vhost two internal addresses
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Scenario: We have two domains and one external IP address and our router NAT'ing.
I need to get apache2 to reverse proxy two internal websites based on which domain they request.
Port 80 is getting answered by 192.168.1.50 (apache) (also domain cam34.com)
This box should also reverse proxy tim.com to 192.168.1.100
Using this virtual host conf file - whenever I enter cam34.com or tim.com I always get tim.com
Hope that makes sense.
Code:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName cam34.com
DocumentRoot /srv/www/htdocs
ErrorLog /var/log/apache2/cam-error_log
CustomLog /var/log/apache2/cam-access_log combined
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName On
# configures the footer on server-generated documents
ServerSignature On
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<proxy>
Order deny,allow
Allow from all
</proxy>
ServerName tim.com
ProxyPass / http://192.168.1.100/
ProxyPassReverse / http://192.168.1.100/
The directive ServerName tim.com which is out side the vhost config takes precedence over any vhost that you have. Best setup is to make tim.com also a vhost, so that you will have proper apache vhost config for both cam34 and tim.
the problem im not hosting tim.com at all. im hosting cam34.com which lives on server 192.168.1.50 while tim.com lives on 192.168.1.100.
All though 192.168.1.50 is recieving port 80 from the external world.
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName On
# configures the footer on server-generated documents
ServerSignature On
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost*:80>
ServerName tim.com
ProxyPass / http://192.168.1.100/
ProxyPassReverse / http://192.168.1.100/
ErrorLog logs/tim.com-error_log
CustomLog logs/tim.com-access_log combined
<proxy>
Order deny,allow
Allow from all
</proxy>
</VirtualHost>
Last edited by chitambira; 02-13-2009 at 05:04 AM..
OMG! Thank you! I have been pulling my hair out trying to get this going!!!
here is my modified httpd.conf from OpenSuse 11.0 with the vhosts.d/ put it to httpd.conf so i could read whats happening!
THANKS AGAIN!!
Code:
Include /etc/apache2/uid.conf
Include /etc/apache2/server-tuning.conf
ErrorLog /var/log/apache2/error_log
Include /etc/apache2/sysconfig.d/loadmodule.conf
Include /etc/apache2/listen.conf
# predefined logging formats
Include /etc/apache2/mod_log_config.conf
# generated from global settings in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/global.conf
# optional mod_status, mod_info
Include /etc/apache2/mod_status.conf
Include /etc/apache2/mod_info.conf
# optional cookie-based user tracking
# read the documentation before using it!!
Include /etc/apache2/mod_usertrack.conf
# configuration of server-generated directory listings
Include /etc/apache2/mod_autoindex-defaults.conf
# associate MIME types with filename extensions
TypesConfig /etc/apache2/mime.types
DefaultType text/plain
Include /etc/apache2/mod_mime-defaults.conf
# set up (customizable) error responses
Include /etc/apache2/errors.conf
Include /etc/apache2/ssl-global.conf
# List of resources to look for when the client requests a directory
DirectoryIndex index.html index.html.var
Include /etc/apache2/default-server.conf
Include /etc/apache2/sysconfig.d/include.conf
<VirtualHost *>
ServerName cam34.com
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /srv/www/htdocs
# if not specified, the global error log is used
ErrorLog /var/log/apache2/mud-error_log
LogLevel Debug
CustomLog /var/log/apache2/mud-access_log combined
LogLevel Debug
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName On
# configures the footer on server-generated documents
ServerSignature On
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *
<VirtualHost *>
ServerName tim.com
ServerAdmin webmaster@dummy-host.example.com
ProxyPass / http://192.168.1.100/
ProxyPassReverse / http://192.168.1.100/
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
# if not specified, the global error log is used
ErrorLog /var/log/apache2/moth-error_log
LogLevel Debug
CustomLog /var/log/apache2/moth-access_log combined
Loglevel Debug
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName On
# configures the footer on server-generated documents
ServerSignature On
#
# This should be changed to whatever you set DocumentRoot to.
#
#<Directory "/srv/www/htdocs">
# Options Indexes FollowSymLinks
# AllowOverride None
# Order allow,deny
# Allow from all
#</Directory>
#ProxyRequests Off
<proxy>
Order deny,allow
Allow from all
</proxy>
</VirtualHost>
Last edited by cam34; 02-19-2009 at 12:18 AM..
Reason: code tags broken?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.