【问题标题】:How to make a subdomain with password on a Ubuntu VPS如何在 Ubuntu VPS 上使用密码创建子域
【发布时间】:2014-08-19 13:25:27
【问题描述】:

您好,我尝试使用 VirtualHost 为我的网站创建一个带有密码的子域。由于某种原因它不起作用,我不知道它为什么会这样。

我应该使用什么? .htaccess 或 VirtualHost

这是我在虚拟主机中尝试过的

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    ServerAdmin example@example.com
    DocumentRoot /var/www/example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


<VirtualHost *:80>
    # Admin email, Server Name (domain name) and any aliases
    ServerAdmin example@example.com
    ServerName  dev.example.com
    DocumentRoot /var/www/example.com/dev/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我是错过了一步还是我做错了什么?

【问题讨论】:

  • 究竟是什么不起作用?子域或密码保护?提供更多详细信息会有所帮助(例如您的 .htacccess 文件):是否显示密码提示?它是否提供内部服务器错误消息?

标签: linux .htaccess ubuntu apache2 subdomain


【解决方案1】:

虚拟主机将使您能够创建子域并将其映射到目录(就像您所做的那样)。

对于通过 .htaccess 进行密码保护,您需要提供必要的配置

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

Source: http://www.htaccesstools.com/articles/password-protection/

要创建 .htpasswd 文件,您可以使用 htpasswd

htpasswd -c .htpassword testuser

【讨论】:

  • 由于某种原因,当我转到子域时,我没有收到登录提示。我也可以在 example.com/dev 访问 dev 子域。我错过了一步吗?
  • 在这里尝试步骤:smartwebdeveloper.com/apache/htaccess-problems 但很可能是由于“Htaccess 被 AllowOverride 设置禁用”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
  • 2021-10-28
  • 2018-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多