authentication - 将 nginx 配置为基于用户身份验证的服务器静态文件
问题描述
我是开发用于提供静态文件的门户的新手。我想将 nginx 配置为基于用户身份验证的服务器静态文件。对于 user1 我希望只能看到 file1 对于 user2 我希望只能看到 file2
My current nginx configuration is:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/files;
autoindex on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ =404;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
[root@webportal files]# pwd
/usr/share/nginx/files
[root@webportal files]# ls -al
total 4
drwxr-xr-x. 2 root root 32 May 5 10:08 .
drwxr-xr-x. 5 root root 46 May 5 09:27 ..
-rw-r--r--. 1 root root 4 May 5 09:45 1.txt
-rw-r--r--. 1 root root 0 May 5 10:08 2.txt
你们能否建议将文件 1.txt 分配给 user1 并将 2.txt 分配给 user2 的最简单方法是什么?基本上,当其中一位用户在门户上进行身份验证时,他只能访问其中一个文件
解决方案
推荐阅读
- ios - 如何在 xcode 中管理版本控制配置?
- reactjs - 如何在 react-router-dom@v6 中使用私有路由
- r - 当应用程序托管在 shinyapps.io 上时,闪亮的应用程序 pdf 输出行距会发生变化
- mysql - 执行更新或删除查询时,Mysql 多次随机崩溃
- python - 如何在 Power BI 中显示使用 Plotly(在 Python 上)制作的桑基图?
- flutter - 在 Dart 的“forEach”和“for”中使用 async/await
- docker - AWS SAM在python中隐藏环境变量
- reactjs - 无法从 rest api 获取 api 并在反应中得到结果
- reactjs - React.useState 中的对象数组如何更新?
- python - 无法使用 PyCall 从 Python 调用 julia 代码,其代码使用 Pycall 回调 python