Nginx 다운로드 권한 오류가-Open()failed(13:권한을 거부)

0

질문

가 웹페이지 Nginx + Uwsgi + Django 어디 외부 경로 불 /download 을 관리 하에서 다운로드 Django(사용자명)고한 내부 경로 /download-nginx 실제로 파일을 다운로드에 있는 디렉토리 /var/wwww/download. 의 이익을 위해 시험을 이렇게 내 사용자 이름뿐만 아니라 기본 nginx 사용자. 모두와 함께 그들의 권한이 거부됨에 오류가 Nginx:

open() "/var/www/download/example.txt" failed (13: Permission denied)

내가 읽은 여러 가지 다른 솔루션을 말하고 그래서는 문제는 제공하는 사용자에 nginx.conf 없는 충분히 권한이 있습니다. 것은 그들이 충분한 권한이 있:

$ sudo -u nginx stat /var

  File: ‘/var’
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 802h/2050d      Inode: 50331745    Links: 21
Access: (0777/drwxrwxrwx)  Uid: (  996/   nginx)   Gid: (    0/    root)
Context: system_u:object_r:var_t:s0
Access: 2021-11-23 11:24:53.329927606 +0000
Modify: 2021-11-23 09:43:29.250244353 +0000
Change: 2021-11-23 11:21:37.151148760 +0000

또한 경우에는 그냥 나가 chmod 777 재귀적으로 디렉토리 /var/wwww/download

nginx.conf 파일은 다음과 같습니다:

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 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    client_max_body_size 128M;
    proxy_max_temp_file_size 0;
    proxy_buffering off;
    server_names_hash_bucket_size 256;

    # 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;

    upstream django {
        server 127.0.0.1:8000;
    }

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

    location /download-nginx {
            internal;
            alias /var/www/download;
            sendfile on;
            proxy_max_temp_file_size 0;
    }

    location / {
        uwsgi_pass django;
        proxy_read_timeout 300s;
        proxy_connect_timeout 75s;
        uwsgi_param Host $host;
        uwsgi_param X-Real-IP $remote_addr;
        uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
        uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;

        uwsgi_param QUERY_STRING $query_string;
        uwsgi_param REQUEST_METHOD $request_method;
        uwsgi_param CONTENT_TYPE $content_type;
        uwsgi_param CONTENT_LENGTH $content_length;
        uwsgi_param REQUEST_URI $request_uri;
        uwsgi_param PATH_INFO $document_uri;
        uwsgi_param DOCUMENT_ROOT $document_root;
        uwsgi_param SERVER_PROTOCOL $server_protocol;
        uwsgi_param HTTPS $https if_not_empty;
        uwsgi_param REMOTE_ADDR $remote_addr;
        uwsgi_param REMOTE_PORT $remote_port;
        uwsgi_param SERVER_PORT $server_port;
        uwsgi_param SERVER_NAME $server_name;
    }

    error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

}

다운로드 보기 내 장고 웹페이지는 다음과 같다,(지만 오류가 나는지 확인에 없는 이 조각):

def download(request):
    # Auth code is ommitted #
    response = HttpResponse()
    path = "/var/www/download/example.txt"
    name = "example.txt"
    response['Content-Length'] = os.path.getsize(path)
    response['X-Accel-Redirect'] = "/download-nginx/{0}".format(name)
    del response['Content-Type']
    del response['Content-Disposition']
    del response['Accept-Ranges']
    del response['Set-Cookie']
    del response['Cache-Control']
    del response['Expires']
    return response

따라서,제 질문은 무엇을 해야에서 내 Centos 기계할 수 있도록하기 위해 데이터에 액세스 /var/www/download 제공하여 사용자는 다운로드 요소가?

centos7 django nginx uwsgi
2021-11-23 14:40:17
1

최고의 응답

0

문제 해결:Nginx 요+x 권한에서의 각 디렉토리입니다. 이는 해결되었으:

sudo chmod +x /var
sudo chmod +x /var/www
sudo chmod +x /var/www/download
2021-11-23 16:13:23

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................