настроить nginx на серверные c файлы на основе аутентификации пользователя - PullRequest
0 голосов
/ 05 мая 2020

Я новичок ie в разработке портала для обслуживания c файлов stati. Я хочу настроить nginx на серверные файлы c на основе аутентификации пользователя. Для пользователя 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 пользователю1 а 2.txt пользователю2? Обычно, когда один из пользователей аутентифицируется на портале, он имеет доступ только к одному из файлов

...