我有一台使用基于名称的虚拟主机的Apache服务器。
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>
当我输入localhost.localdomain和localhost1.localdomain时,我分别从文件夹/ var / www / localhost和/ var / www / localhost1获取了正确的页面。但后来我做了
ssh -L 0.0.0.0:10080:localhost.localdomain:80 -L 0.0.0.0:10081:localhost1.localdomain:80 localhost
localhost:10080和localhost:10081都会得到/ var / www / localhost的答案。尽管通过SSH隧道连接,是否可以让Apache识别域?
答案 0 :(得分:7)
您需要将Apache vhost ServerName与您在浏览器地址栏中输入的内容相匹配。
假设这个vhost:
ServerName foo.com
然后在您的本地/ etc / hosts文件中:
127.0.0.1 foo.com
然后
ssh -L8080:127.0.0.1:80 user@apache
然后
wget http://foo.com:8080
现在请求是使用Host:foo.com进行的,它应该是正确的vhost。