用于开发目的的 Symfony2 简单 .htaccess 密码保护
Symfony2 simple .htaccess password protect for dev purpose
我想在开发时使用 .htaccess
文件来保护我的 symfony2 网站。
我在位于 /web
的 .htaccess
开头添加了以下行,紧接着添加了一个 .htpasswd
文件和我的密码。
AuthName "Développement"
AuthType Basic
AuthUserFile ".htpasswd"
Require valid-user
当我尝试访问我的网站时出现错误 500。在我的案例中可以使用 htaccess 吗?如果不可行我应该使用什么?
假设 500 错误是由这些指令引起的,最可能的原因是 .htpasswd
的路径。 AuthUserFile
说
The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.
因此要么使用绝对路径(例如 /var/www/.htpasswd
),要么添加从文档根目录开始的完整路径(例如 web/.htpasswd
)。
另请注意 AuthUserFile
中的最后一节
Security
Make sure that the AuthUserFile is stored outside the document tree of the web-server. Do not put it in the directory that it protects. Otherwise, clients may be able to download the AuthUserFile.
这意味着,将 auth 文件存储在其他地方,例如 /etc/apache2/htpasswd
。
我想在开发时使用 .htaccess
文件来保护我的 symfony2 网站。
我在位于 /web
的 .htaccess
开头添加了以下行,紧接着添加了一个 .htpasswd
文件和我的密码。
AuthName "Développement"
AuthType Basic
AuthUserFile ".htpasswd"
Require valid-user
当我尝试访问我的网站时出现错误 500。在我的案例中可以使用 htaccess 吗?如果不可行我应该使用什么?
假设 500 错误是由这些指令引起的,最可能的原因是 .htpasswd
的路径。 AuthUserFile
说
The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.
因此要么使用绝对路径(例如 /var/www/.htpasswd
),要么添加从文档根目录开始的完整路径(例如 web/.htpasswd
)。
另请注意 AuthUserFile
Security
Make sure that the AuthUserFile is stored outside the document tree of the web-server. Do not put it in the directory that it protects. Otherwise, clients may be able to download the AuthUserFile.
这意味着,将 auth 文件存储在其他地方,例如 /etc/apache2/htpasswd
。