Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 将nginx配置为基于用户身份验证的服务器静态文件_Authentication_Nginx_Static Files - Fatal编程技术网

Authentication 将nginx配置为基于用户身份验证的服务器静态文件

Authentication 将nginx配置为基于用户身份验证的服务器静态文件,authentication,nginx,static-files,Authentication,Nginx,Static Files,我是一个为静态文件开发门户的新手。 我想将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 R

我是一个为静态文件开发门户的新手。 我想将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吗?
基本上,当其中一个用户在门户上进行身份验证时,他只能访问其中一个文件

,用户名可用作
$remote\u user
。您可以使用
映射
来识别每个用户应该看到的文本文件。谢谢@RichardSmith,我找到了我需要的:用户名是
$remote\u user
。您可以使用
地图
来确定每个用户应该看到的文本文件。谢谢@RichardSmith,我找到了我需要的: