[5] Nginx 서버 셋업 - Web에서 서버 폴더 리스팅
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
업/다운로드를 구현 하기 전 우선 장비 local 저장소를 만들고 해당 저장소를 web에서 볼수있게 먼저 정의한다
1. 저장소 생성 및 권한 부여
- 저장소 생성 ``` mkdir /root/storage cd /root/storage vi test.txt ( 적당히 아무값 넣고 저장 종료 ) ```
- nginx가 뜬 user권한을 폴더에 부여 ``` ps aux | grep nginx
# 제 경우는 nobody 이므로 해당 폴더 소유주 변환 [root@vbox build] (master) $ ps aux | grep nginx root 52636 0.0 0.0 4544 2412 ? Ss 01:26 0:00 nginx: master process ./nginx root 59772 0.0 0.1 13064 9600 pts/1 T 06:04 0:00 /usr/bin/vim nginx.conf nobody 60676 0.0 0.0 13168 5484 ? S 06:23 0:00 nginx: worker process nobody 60677 0.0 0.0 13168 5612 ? S 06:23 0:00 nginx: worker process
# 권한 및 소유주 변환 sudo chmod -R 755 /root/storage sudo chown -R nobody:nobody /root/storage
# SELinux 보안 컨텍스트 수정 sudo chcon -R -t httpd_sys_content_t /root/storage
```
위 작업들을 수행하지 않으면, 403 Fobbiden을 맞게된다
2. Nginx 설정 적용
- alias 통해, list api 가 들어오면 /root/storage의 경로를 보여준다
``` user nobody; worker_processes 10;
events { worker_connections 1024; use epoll; }
http { include mime.types; default_type application/octet-stream;
sendfile on; keepalive_timeout 65; large_client_header_buffers 4 16k;
server { listen 10099; server_name localhost;
location /upload.html { root /root/nginx/html; index upload.html;
}
location /list { alias /root/storage/; autoindex on; # 디렉터리 인덱스 표시 autoindex_exact_size off; # 파일 크기를 간소화된 형식으로 표시 (선택사항) autoindex_localtime on; # 로컬 시간으로 파일 시간 표시 (선택사항) }
location /upload { proxy_pass http://localhost:8848; # 프록시할 대상 서버 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
} }
```
수정 이후 nginx -s reload 적용
확인 해보면 잘나온다
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
댓글
댓글 쓰기