Apache VirtualHost: How to ServerName a port diffe

2019-06-03 10:57发布

I use Xampp and I want test.localhost to go to 127.0.0.1:81.

In httpd.conf I wrote:

Listen 127.0.0.1:81
NameVirtualHost 127.0.0.1:81
<VirtualHost 127.0.0.1:81>
 ServerName test.localhost
 DocumentRoot "d:\_projects\projectx"
 DirectoryIndex index.php
</VirtualHost>

and to windows\system32\drivers\etc\hosts I added:

127.0.0.1       test.localhost

But http://test.localhost now brings me to 127.0.0.1:80.

How do I make it go to 127.0.0.1:81?

2条回答
孤傲高冷的网名
2楼-- · 2019-06-03 11:20

As far as your browser is concerned, http://test.localhost is http://test.localhost:80.

What you want is an Apache redirect...

<VirtualHost 127.0.0.1:80>
 ServerName test.localhost

 Redirect / http://test.localhost:81
</VirtualHost>
查看更多
狗以群分
3楼-- · 2019-06-03 11:42

Or just go http://test.localhost:81 on your browser instead of using Redirect.

查看更多
登录 后发表回答