Development Tip

일종의 '파일 브라우저'모드를 사용하도록 nginx를 구성하는 방법은 무엇입니까?

yourdevel 2020. 11. 14. 11:13
반응형

일종의 '파일 브라우저'모드를 사용하도록 nginx를 구성하는 방법은 무엇입니까?


이전에 URL을 입력 할 때 이것을 본 적이 있으면 http://test.com/test/html 페이지를 제공하는 대신 주어진 위치에있는 모든 파일을 탐색 할 수있는 인터페이스와 같은 '파일 브라우저'를 제공합니다.

위치 컨텍스트에서 사용할 수있는 nginx 모듈 일 수 있다고 생각합니다.

nginx.conf파일 :

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  122.97.248.252;
                location /test {
                        root /home/yozloy/html/;
                        autoindex on;
                }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

업데이트 error.log

2012/05/19 20:48:33 [오류] 20357 # 0 : * 72 open () "/ home / yozloy / html / test"실패 (2 : 해당 파일 또는 디렉토리 없음), 클라이언트 : 125.43.236.33, 서버 : 122.97.248.252, 요청 : "GET / test HTTP / 1.1", 호스트 : "unicom2.markson.hk

위치 /test의미 를 오해해야합니다. http://example.com/test를 입력했을 때 의미한다고 생각 하면 루트 사전에 액세스합니다./home/yozloy/html/


HttpAutoindexModule을 시도해야합니다.

자동 색인 옵션을로 설정합니다 on. 기본적으로 꺼져 있습니다.

예제 구성이 정상이어야합니다.

location /{ 
   root /home/yozloy/html/; 
   index index.html; 
   autoindex on;
}

autoindex 옵션이 없으면 파일 /이없는 디렉토리에서 끝나는 요청에 대해 오류 403 이 표시 index.html됩니다. 이 옵션을 사용하면 간단한 목록이 표시됩니다.

<html>
<head><title>Index of /</title></head>
<body bgcolor="white">
<h1>Index of /test/</h1><hr><pre><a href="../">../</a>
<a href="test.txt">test.txt</a>                 19-May-2012 10:43            0
</pre><hr></body>
</html>

편집 : 테스트 할 참조를 삭제하도록 목록을 업데이트했습니다 .


1. 모든 디렉토리의 내용 나열

자동 색인 옵션을로 설정합니다 on. 기본적으로 꺼져 있습니다.

구성 파일 ( vi /etc/nginx/sites-available/default)은 다음과 같아야합니다.

location /{ 
   ... ( some other lines )
   autoindex on;
   ... ( some other lines )
}

2. 일부 특정 디렉토리의 내용 만 나열

자동 색인 옵션을로 설정합니다 on. 기본적으로 꺼져 있습니다.

구성 파일 ( vi /etc/nginx/sites-available/default)
은 다음과 같아야합니다. 디렉토리 경로로
변경path_of_your_directory

location /path_of_your_directory{ 
   ... ( some other lines )
   autoindex on;
   ... ( some other lines )
}

도움이 되었기를 바랍니다 ..


/home/yozloy/html/test폴더 생성이 필요 합니다. 또는 alias아래와 같이 사용할 수 있습니다 .

location /test {
    alias /home/yozloy/html/;
    autoindex on;
}

All answers contain part of the answer. Let me try to combine all in one.

Quick setup "file browser" mode on freshly installed nginx server:

  1. Edit default config for ngingx:

    sudo vim /etc/nginx/sites-available/default
    
  2. Add following to config section:

    location /myfolder {  # new url path
       alias /home/username/myfolder/; # directory to list
       autoindex on;
    }
    
  3. Create folder and sample file there:

    mkdir -p /home/username/myfolder/
    ls -la >/home/username/myfolder/mytestfile.txt
    
  4. Restart nginx

    sudo systemctl restart nginx
    
  5. Check result: http://<your-server-ip>/myfolder for example http://192.168.0.10/myfolder/

enter image description here


I've tried many times.

And at last I just put autoindex on; in http but outside of server, and it's OK.


Just add this section to server, just before the location / {

location /your/folder/to/browse/ {
        autoindex on;
}

참고URL : https://stackoverflow.com/questions/10663248/how-to-configure-nginx-to-enable-kinda-file-browser-mode

반응형