使用nginx. htaccess身份验证


.htaccess authentication with nginx

我的配置有一些问题。我使用Nginx作为我的Apache服务器的反向代理。我的网站有。htaccess认证,但Nginx似乎不理解它,所以我得到一个404错误。

我看到一些翻译在其他的答案,但它没有翻译这一部分。

AuthUserFile /var/www/mywebsite/private/.htpassword
AuthName "Acces Restreint" 
AuthType Basic
Require valid-user

顺便问一下,你知道第二部分怎么翻译吗?

php_value session.gc_maxlifetime 604800
SetEnv APPLICATION_ENV development

感谢大家的帮助

对于性能相关的问题,nginx默认不查找每个目录的。htaccess文件,这是一个问题,如果你的主机不允许你编辑webserver配置。

如果你可以编辑webserver配置(或者把新的配置放入conf.d目录)只需添加这些行,相应替换/your/path

 location  /your/path  {
   auth_basic            "Acces Restreint";
   auth_basic_user_file  /var/www/mywebsite/private/.htpassword;
 }

回答你问题的第二部分需要更多关于如何在nginx中使用PHP的信息。如果你使用FastCGI(例如PHP -fpm),那么你可以使用这个方法来设置PHP的变量:

 fastcgi_param  PHP_VALUE  "session.gc_maxlifetime=604800";

 env APPLICATION_ENV development;