Symfony2简单的.htaccess密码保护用于开发目的 [英] Symfony2 simple .htaccess password protect for dev purpose

查看:80
本文介绍了Symfony2简单的.htaccess密码保护用于开发目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在开发时使用 .htaccess 文件保护我的symfony2网站。

I would like to use a .htaccess file to protect my symfony2 website while developing it.

我在 / web中的 .htaccess 的开头添加了以下行和一个 .htpasswd 文件紧跟着我的密码。

I added the following line at the beginning of my .htaccess located in /web and a .htpasswd file just next with my password.

AuthName "Développement"
AuthType Basic
AuthUserFile ".htpasswd"
Require valid-user

当我尝试访问我的网站时出现错误500。我可以使用htaccess吗?

I have a Error 500 when I try to access my website. Is it possible to use a htaccess in my case ? What should I use if it is not posible ?

推荐答案

假设500错误是由这些指令引起的,最可能的原因是: .htpasswd 的路径。 AuthUserFile

Assuming the 500 error is caused by these directives, the most likely reason is the path to .htpasswd. AuthUserFile says


AuthUserFile指令设置文本文件的名称,该文本文件包含用户列表和用于用户认证的密码。 File-path是用户文件的路径。 如果不是绝对的,则将其视为相对于 ServerRoot

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 )。

So either use an absolute path (e.g. /var/www/.htpasswd) or add the complete path starting from your document root (e.g. web/.htpasswd).

还要注意 AuthUserFile


安全性

确保AuthUserFile存储在Web服务器的文档树之外。不要将其放在其保护的目录中。否则,客户端可能可以下载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

This means, store the auth file somewhere else, like /etc/apache2/htpasswd.

这篇关于Symfony2简单的.htaccess密码保护用于开发目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆