Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ssh

apache

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?

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

AssA


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:

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.

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

Jukka