How to make Apache recognize a domain when connecting through an SSH tunnel?

I have an Apache server that uses 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 correct pages from the / var / www / localhost and / var / www / localhost1 folders 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 

Both localhost: 10080 and localhost: 10081 both result in a response from / var / www / localhost. Is it possible that Apache recognizes domains despite connecting through an SSH tunnel?

+4
source share
1 answer

You need to map the name of the Apache vhost server to what you type in the address bar of the browser.

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 executed with Host: foo.com, and it should get into the correct vhost.

+7
source

Source: https://habr.com/ru/post/1483599/


All Articles