如何使用Nginx进行身份验证的用户目录

前端之家收集整理的这篇文章主要介绍了如何使用Nginx进行身份验证的用户目录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用基于Debian的主机并使用NginxPHP-FPM,我想在Nginx中启用用户目录,并希望多用户支持基本身份验证.这意味着Alex打开www.example.com/rutorrent;这将提示登录和密码,并在验证后,这应该指向他自己的PHP脚本版本位于/ home / alex / www / rutorrent,当Bob将打开www.example.com/rutorrent;这将提示登录和密码和身份验证后这应该指向他的PHP脚本位于/ home / bob / www / rutorrent.

我已经尝试过这里的官方文档:
http://wiki.nginx.org/UserDir

但我不确定如何将它们配置为默认文件,以便我可以获得我想要的功能,我的默认配置文件Nginx在这里:

  1. server {
  2. server_name localhost;
  3. location / {
  4. try_files $uri $uri/ /index.html;
  5. }
  6. location /doc/ {
  7. alias /usr/share/doc/;
  8. autoindex on;
  9. allow 127.0.0.1;
  10. allow ::1;
  11. deny all;
  12. }
  13. index index.PHP index.html index.htm;
  14. location ~ ^/~([^/]*)(.*)\.PHP${
  15. fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
  16. fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  17. auth_basic "Restricted";
  18. auth_basic_user_file /etc/Nginx/sites-available/.htpasswd;
  19. fastcgi_param SCRIPT_FILENAME /home/$1/www$2.PHP;
  20. include fastcgi_params;
  21. }
  22. location ~ ^/~([^/]*)(.*) {
  23. autoindex on;
  24. alias /home/$1/www$2;
  25. auth_basic "Restricted";
  26. auth_basic_user_file /etc/Nginx/sites-available/.htpasswd;
  27. }
  28. location /RPC2 {
  29. include scgi_params;
  30. scgi_pass localhost:5000;
  31. }
  32. }

有没有办法得到这个?

最佳答案
感谢帮助我,我有线索修复用户目录问题,我在主Nginx配置文件中使用$remote_user变量,在$remote_user变量中使用Nginx捕获用户名,同时我们使用基本身份验证,因此非常好用且易于使用用户目录如果我们以这种方式包括

  1. /home/$remote_user/..

猜你在找的Nginx相关文章