IT

Nginx 403 오류 : [폴더]의 디렉토리 색인이 금지되어 있습니다.

lottoking 2020. 6. 10. 07:59
반응형

Nginx 403 오류 : [폴더]의 디렉토리 색인이 금지되어 있습니다.


나는 3 개의 도메인 이름을 가지고 있으며 Nginx를 사용하여 하나의 서버 (Digital Ocean droplet)에서 3 개의 사이트를 모두 호스팅하려고합니다.

mysite1.name mysite2.name mysite3.name

그들 중 하나만 작동합니다. 다른 두 결과는 같은 방법으로 403 오류를 발생시킵니다.

내 nginx 오류 로그에 다음이 표시 [error] 13108#0: *1 directory index of "/usr/share/nginx/mysite2.name/live/" is forbidden됩니다.

내 사이트 사용 구성은 다음과 같습니다.

server {
        server_name www.mysite2.name;
        return 301 $scheme://mysite2.name$request_uri;
}
server {
        server_name     mysite2.name;

        root /usr/share/nginx/mysite2.name/live/;
        index index.html index.htm index.php;

        location / {
                try_files $uri $uri/ /index.html index.php;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

3 개 사이트 모두 구성 파일이 거의 동일합니다.

각 사이트의 파일은 /usr/share/nginx/mysite1.name/someFolder와 같은 폴더에 있으며 /usr/share/nginx/mysite1.name/live는 해당 파일에 대한 심볼릭 링크입니다. (mysite2 및 mysite3과 동일합니다.)

Nginx 403이 모든 파일에 대해 금지되어있는 것을 보았지만 도움이되지 않았습니다.

무엇이 잘못되었을 지에 대한 아이디어가 있습니까?


디렉토리 색인이 해제되어 있고이 문제점이 발생하는 경우, 사용중인 try_files에 디렉토리 옵션이 있기 때문일 수 있습니다.

location / {
  try_files $uri $uri/ /index.html index.php;
}                 ^ that is the issue

그것을 제거하면 작동합니다 :

location / {
  try_files $uri /index.html index.php;
} 

내가 볼 수 있듯이, 이것은 nginx가 디렉토리를 색인화하려고 시도하고 자체적으로 차단되기 때문에 발생합니다. OP에서 언급 한 오류가 발생했습니다.


작동하는 구성은 다음과 같습니다.

server {
    server_name www.mysite2.name;
    return 301 $scheme://mysite2.name$request_uri;
}
server {
    #This config is based on https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf
    server_name mysite2.name;

     # The location of our project's public directory.
    root /usr/share/nginx/mysite2/live/public/;

     # Point index to the Laravel front controller.
    index           index.php;

    location / {
        # URLs to attempt, including pretty ones.
        try_files   $uri $uri/ /index.php?$query_string;
    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
            rewrite     ^/(.+)/$ /$1 permanent;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #   # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param                   scriptFILENAME $document_root$fastcgi_scriptname;
    }

}

그런 다음 브라우저의 유일한 출력은 Laravel 오류입니다.“후프, 문제가있는 것 같습니다.”

실행하지 마십시오 chmod -R 777 app/storage( 참고 ). 세상에 쓸 수있는 무언가를 만드는 것은 안보가 좋지 않습니다.

chmod -R 755 app/storage 작동하고 더 안전합니다.


단순히 디렉토리 내용을 나열하려는 경우 다음 autoindex on;과 같이 사용하십시오 .

location /somedir {
       autoindex on;
}

server {
        listen   80;
        server_name  domain.com www.domain.com;
        access_log  /var/...........................;
        root   /path/to/root;
        location / {
                index  index.php index.html index.htm;
        }
        location /somedir {
               autoindex on;
        }
}

/var/log/nginx/error.log의 오류 로그에서 비슷한 오류가 발생했습니다.
--- 웹 페이지에서 "403 Forbidden"
--- "13 : 권한이 거부되었습니다"

3 단계 미만이 나를 위해 일했습니다.

1 : 터미널을 열고 아래와 같은 것을 보았습니다.

user1@comp1:/home/www/

내 사용자 이름은 "user1"입니다 (위에서).

2 : /etc/nginx/nginx.conf에서 변경된 사용자

# user www-data;
user user1;

3 : nginx를 다시로드

sudo nginx -s reload  

또한 파일 / 폴더 권한을 (3 단계 이상 전에)
(755 / 내 디렉토리에 / dir1 /) 및 (644 해당 디렉토리 아래의 파일에) 적용했습니다.
(이 추가 단계가 실제로 있는지 확실하지 않습니다. 3 단계 이상이면 충분할 수 있습니다.)

chmod 755 ./dir1/
chmod 644 ./dir1/*.*

이것이 빠른 누군가를 돕기를 바랍니다. 행운을 빌어 요.


실제로 몇 가지 확인해야 할 사항이 있습니다. 1. nginx의 실행 상태를 확인하십시오

ps -ef|grep nginx

ps aux|grep nginx|grep -v grep

여기서 nginx를 실행중인 사람을 확인해야합니다. 사용자와 그룹을 기억하십시오

  1. 폴더의 액세스 상태 확인

    ls -alt

  2. 폴더 상태를 nginx와 비교

(1) 폴더의 액세스 상태가 올바르지 않은 경우

sudo chmod 755 /your_folder_path

(2) 폴더의 사용자와 그룹이 nginx의 실행중인 것과 동일하지 않은 경우

sudo chown your_user_name:your_group_name /your_folder_path

nginx의 실행중인 사용자 이름과 그룹을 변경하십시오.

nginx -h

nginx 구성 파일이 어디에 있는지 찾기 위해

sudo vi /your_nginx_configuration_file

//in the file change its user and group
user your_user_name your_group_name;

//restart your nginx
sudo nginx -s reload

nginx 기본 실행 사용자는 nobody이고 group은 nobody이기 때문입니다. 이 사용자와 그룹을 모르면 403이 도입됩니다.


나는 같은 문제가 있었고 로그 파일은이 오류를 보여주었습니다.

2016/03/30 14:35:51 [error] 11915#0: *3 directory index of "path_scripts/viewerjs/" is forbidden, client: IP.IP.IP.IP,     server: domain.com, request: "GET /scripts/viewerjs/ HTTP/1.1", host: "domain", referrer: "domain.com/new_project/do_update"

codeignitor 프레임 워크가있는 PHP 앱을 호스팅하고 있습니다. 업로드 된 파일을보고 싶을 때 403 Error.

문제는 nginx.conf제대로 정의되지 않았다는 것입니다. 대신에

index index.html index.htm index.php

나는 포함했다

index index.php

나는 내 루트에 index.php가 있고 충분하다고 생각했다. 나는 틀렸다;) 힌트는 나에게 NginxLibrary를 주었다.


Nginx 정책 (예 : "거부")으로 인해이 오류가 발생하거나 Nginx 구성 오류로 인해이 오류가 발생하거나 파일 시스템 제한으로 인해이 문제가 발생할 수 있습니다.

나중에 최신 버전인지 확인할 수 있습니다 (그리고 strace를 사용하여 구성이 잘못되었다는 증거를 볼 수 있습니다 (단, OP가 액세스 할 수 없음)).

# pidof nginx
11853 11852

# strace -p 11853 -p 11852 -e trace=file -f
Process 11853 attached - interrupt to quit
Process 11852 attached - interrupt to quit
[pid 11853] stat("/var/www/html/kibanaindex.html", 0x7ffe04e93000) = -1 ENOENT (No such file or directory)
[pid 11853] stat("/var/www/html/kibana", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
^CProcess 11853 detached
Process 11852 detached

여기서는 테스트를 실행하는 동안 nginx가 수행 한 파일 시스템 활동을 검사하고 있습니다 (귀하와 같은 오류가 발생했습니다).

다음은 구성에서 선택한 부분입니다.

    location /kibana/3/ {
        alias /var/www/html/kibana;
        index index.html;
    }

필자의 경우 strace가 명확하게 보여 주듯이 "alias"에서 "index"에 합류하는 것은 내가 예상 한 것이 아니며 항상 /로 디렉토리 이름을 추가하는 습관을들이는 것처럼 보입니다. 내 경우에는 다음이 효과가있었습니다.

    location /kibana/3/ {
        alias /var/www/html/kibana/;
        index index.html;
    }

권한 문제처럼 보입니다.

mysite1에서했던 것처럼 모든 permisions를 다른 사이트로 설정하십시오.

기본적으로 파일 권한은 644와 dirs 755 여야합니다. nginx를 실행하는 사용자에게 해당 파일과 디렉토리를 읽을 수있는 권한이 있는지 확인하십시오.


을 사용 php-fpm하고 있으므로 php-fpm사용자가 사용자와 동일한 지 확인해야합니다 nginx.

/etc/php-fpm.d/www.confPHP 사용자 및 그룹이 nginx아닌지 확인 하고 설정 하십시오 .

php-fpm사용자가 쓰기 권한이 필요합니다.


변경 try_files받는 점을 index.php당신이 이런 식으로 뭔가해야 언급하는 "Laravel"에, 경로

location / {
    try_files $uri $uri/ /public/index.php$request_uri;
}

"codeigniter"프로젝트에서 다음과 같이 해보십시오

location / {
    try_files $uri $uri/ /public_web/index.php$request_uri;
}

정적 파일 디렉토리에 대한 실행 권한이 필요합니다. 또한 nginx 사용자 및 그룹에 의해 chown'ed해야합니다.


location ~* \.php$ {
    ...
    fastcgi_param scriptFILENAME $document_root$fastcgi_scriptname;    
}

기본값 변경

fastcgi_param  scriptFILENAME  /scripts$fastcgi_scriptname;

fastcgi_param scriptFILENAME $document_root$fastcgi_scriptname;

내 문제를 해결했다.


6833#0: *1 directory index of "/path/to/your/app" is forbidden, client: 127.0.0.1, server: lol.com, request: "GET / HTTP/1.1", host: "localhost"    

우분투 15.10을 실행 중이며 간단한 이유로 403 Forbidden 오류가 발생했습니다. nginx.conf (nginx 구성 파일)에서 사용자는 'www-data'였습니다. 사용자 이름을 [my username (사용자 이름)]으로 변경 한 후에는 필요한 사용 권한이 사용자 이름에 부여되었다고 가정했을 때 정상적으로 작동했습니다. 다음 단계 :

chmod 755 /path/to/your/app    

내 구성 파일은 다음과 같습니다.

**user [my username]**;#I made the change here.
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

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

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;


server {
    listen 80;

    server_name My_Server;

    access_log  /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;

    location / {
        proxy_pass         http://127.0.0.1:8000;
        proxy_redirect     off;

        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}
}

이 문제를 해결하기 위해 밤새도록 보냈습니다. 이 이야기에 내 두 센트가 있습니다.

PHP 인터프리터로 hhvm사용하고 있는지 확인하십시오 . 그런 다음 포트 9000에서 수신 대기 중일 수 있으므로 웹 서버의 구성을 수정해야합니다.

참고 사항 : mysql을 사용하고 있고 hhvm에서 mysql 로의 연결이 불가능 해지면 apparmor가 설치되어 있는지 확인하십시오 . 비활성화하십시오.


For me the problem was that any routes other than the base route were working, adding this line fixed my problem:

index           index.php;

Full thing:

server {

    server_name example.dev;
    root /var/www/example/public;
    index           index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param scriptFILENAME $document_root$fastcgi_scriptname;
    }
}

I resolved my problem, if i configure like follow:

location = /login {
    index  login2.html;
}

It'll show the 403 error.

[error] 4212#2916: *2 directory index of "D:\path/to/login/" is forbidden

I've tried autoindex on, but not working. If i change my configure like this, it works.

location = /login/ {
    index  login2.html;
}

I think the exact matching, if it's a path should be a directory.


when you want to keep the directory option,you can put the index.php ahead of $uri like this.

try_files /index.php $uri $uri/

location / {
root  fileLocation;
index  index.html index.htm;
expires 0;
if_modified_since off;}

Here I used alias instead of root and that caused me the error. This configuration works fine.

참고URL : https://stackoverflow.com/questions/19285355/nginx-403-error-directory-index-of-folder-is-forbidden

반응형