简体   繁体   中英

.htaccess authentication with nginx

I've some issues with my configuration. I'm using Nginx as a reversed proxy for my Apache server. My website has .htaccess authentication but Nginx doesn't seem to understand it so I'm getting a 404 error.

I saw some translators on other answers but it doesn't translate this part.

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

By the way, do you have any idea about how to translate this second part ?

php_value session.gc_maxlifetime 604800

SetEnv APPLICATION_ENV development

Thanks everyone for your help !

for perfomance related issues, nginx by default does not look up per-directory .htaccess files , which is a problem if your hosting does not let you edit webserver config.

if you can edit webserver config (or put new config into conf.d dir) just add these lines, replacing /your/path correspondingly

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

answering second part of your question needs more info on how you use PHP with nginx. if you are tied to FastCGI (eg php-fpm), then you can use this method to set PHP' vars:

 fastcgi_param  PHP_VALUE  "session.gc_maxlifetime=604800";


 env APPLICATION_ENV development;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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