简体   繁体   English

Apache-如何在没有htaccess的情况下保护virtualhost指令

[英]Apache - How to protect virtualhost directive without htaccess

I would like to password protect port 2000 of a web server by embedding a location directive inside of the virtualhost directive of the apache config file. 我想通过嵌入Apache的配置文件的虚拟主机指令的内部位置指令密码保护Web服务器的2000端口。 However it didn't prompt for a password as expected. 但是,它没有提示输入预期的密码。 This is what I had in the apache config file: 这是我在apache配置文件中的内容:

<VirtualHost *:2000>
  ServerName www.server.com
  ServerAdmin email
  DocumentRoot /var/www/html
  ErrorLog logs/server.com-error_log

  <Location / >
    AuthType Basic
    AuthName "Security"
    AuthUserFile /var/www/s2/.htpasswd-users
    Require valid-user
  </Location>
</VirtualHost>

A couple reasons why I think it didn't work: 我认为它不起作用的几个原因:

  1. I needed a corresponding NameVirtualHost *:2000 to go with the VirtualHost directive 我需要一个对应的NameVirtualHost *:2000来配合VirtualHost指令
  2. I was using a reverse ssh tunnel on that port so ssh was catching it before the web server. 我在该端口上使用了反向ssh隧道,因此ssh在Web服务器之前捕获了它。 The web server that the tunnel connected to did not have password protection. 隧道连接到没有密码保护的Web服务器。

So now my question is how to password protect the server at the end of the tunnel. 所以现在我的问题是如何在隧道尽头用密码保护服务器。 It is a simple server and not capable of passwords. 这是一台简单的服务器,没有密码。 That's why I was hoping to protect access to it via the apache server. 这就是为什么我希望保护通过apache服务器对其的访问。

AuthType only works inside or in a .htaccess file: AuthType仅适用于.htaccess文件内部或内部:

You have it inside a and that's the rease it isn't working. 您将其包含在中,这是它无法正常工作的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM