I have an Apache server which is using name-based virtual hosts.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/localhost
ServerName localhost.localdomain
ServerAlias localhost.localdomain
ErrorLog logs/localhost_error_log
CustomLog logs/localhost_access_log common
<Directory /var/www/localhost1>
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost1.localdomain
ServerAlias localhost1.localdomain
DocumentRoot /var/www/localhost1
ErrorLog logs/localhost1_error_log
CustomLog logs/localhost1_access_log common
<Directory /var/www/localhost1>
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
When I type localhost.localdomain and localhost1.localdomain I get the proper pages from the folders /var/www/localhost and /var/www/localhost1 respectively. But then I do
ssh -L 0.0.0.0:10080:localhost.localdomain:80 -L 0.0.0.0:10081:localhost1.localdomain:80 localhost
And localhost:10080 and localhost:10081 both result in the answer from /var/www/localhost. Is it possible to make Apache recognize the domains despite connecting through SSH tunnel?
You need to match the Apache vhost ServerName with what you type into your browsers address bar.
Assuming this vhost:
ServerName foo.com
Then in your local /etc/hosts file:
127.0.0.1 foo.com
Then
ssh -L8080:127.0.0.1:80 user@apache
Then
wget http://foo.com:8080
Now the request is made with Host: foo.com and it should hit the correct vhost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With