Logo Questions Linux Laravel Mysql Ubuntu Git Menu

How to make Apache recognize domain when connecting through SSH tunnel? [closed]




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
<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

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 -L 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?

like image 496
AssA Avatar asked Mar 24 '23 18:03


1 Answers

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:  foo.com


ssh -L8080: user@apache


wget http://foo.com:8080

Now the request is made with Host: foo.com and it should hit the correct vhost.

like image 118
Jukka Avatar answered Mar 26 '23 09:03