일종의 '파일 브라우저'모드를 사용하도록 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:
Edit default config for ngingx:
sudo vim /etc/nginx/sites-available/default
Add following to config section:
location /myfolder { # new url path alias /home/username/myfolder/; # directory to list autoindex on; }
Create folder and sample file there:
mkdir -p /home/username/myfolder/ ls -la >/home/username/myfolder/mytestfile.txt
Restart nginx
sudo systemctl restart nginx
Check result:
http://<your-server-ip>/myfolder
for example http://192.168.0.10/myfolder/
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;
}
'Development Tip' 카테고리의 다른 글
NetBeans 스캔 프로젝트를 중지하는 방법이 있습니까? (0) | 2020.11.14 |
---|---|
mongodump에서 덤프 된 데이터를 사용하는 방법은 무엇입니까? (0) | 2020.11.14 |
PowerShell에서 줄을 나누는 방법은 무엇입니까? (0) | 2020.11.14 |
커밋 내역과 함께 파일 및 디렉토리를 하위 디렉토리로 이동 (0) | 2020.11.14 |
Node.js-최대 호출 스택 크기 초과 (0) | 2020.11.14 |