我正在用C语言编写一个社交网站,并用Nginx来提供。 我该如何做到这一点,以便通过身份validation的用户可以访问他们自己的目录 – 只有用户特定的index.html所在的目录。 我不是问如何用特定于用户的指令填充index.html,而是如何将它们locking到自己的目录中
map $remote_user $profile_directory { default $remote_user; '' guests; pavel admins; ivan admins; } server { location /profile/ { alias /path/to/www/$profile_directory/; ... } }
第二个例子(见评论):
server { location / { auth_basic "Please Login"; auth_basic_user_file "/etc/nginx/htpasswd"; root /var/www/sites/mysite.com/http/$remote_user; } }
events { } http { map $remote_user $profile_directory { default $remote_user; } server { root /var/www/sites/mysite.com/http; location / { auth_basic "Please Login"; auth_basic_user_file "/etc/nginx/htpasswd"; alias /var/www/sites/mysite.com/http/$profile_directory/; } } }
这是我的编辑版本,其中包括我的整个裸骨头nginx.conf