| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
- Linux
- RDB
- postgresql
- Failed to load ApplicationContext
- #mojo
- spring boot
- Docker
- JWT
- postgres
- QGIS
- Geoserver
- uuid
- hadoop #hdfs
- nginx
- posgis
- sftp
- 1093
- psycopg2
- Kafka
- spring
- python
- LazyInitializationException
- insert into
- mysql
- JPA
- Spring Security
- Java
- JSON Web Token
- Maven
- AuthenticationPrincipal
- Today
- Total
FOREST_CHOI's BLOG
Nginx 파일 다운로드 서버 구축하기 - SIMPLE 본문
간단하게 NGINX로 몇 가지 파일 다운로드 서버를 구축해 보았다.
일단 이 예제는 Localhost 에 올려놓고 테스트 용으로 사용가능한 예제이다.
일단 NGINX는 Docker를 이용하여 띄울 것이므로, Docker는 필수로 설치 되어있어야한다.
1. Nginx Setup(For docker)
version: "3"
services:
web:
image: nginx
ports:
- 8989:80
volumes:
- ./:/usr/share/nginx/html/
restart: always
8080은 많이들 사용한다고 생각해서 8989로 포트를 지정해 놓았다.
docker-compose.yml 파일을 저장하는 경로와 NGINX /usr/share/nginx/html를 volume으로 묶어놓았다.
이정도로 간단하게만 설정 해 두어도 충분히 돌아가는 webservser가 올라간다.
2. 다운로드 할 파일을 올려놓을 Download 폴더 만들기
- mkdir downloads 를 이용해서 폴더를 하나 생성해 주었다.

용량이 큰 파일도 다운로드가 되는지 확인하기위해 ubuntu iso도 올려보았다.
-> touch test.log
-> echo "test" >> test.log
를 사용해서 간단한 log 파일을 만들어 놓는다.
3. conf 파일 설정하기
conf 파일은 아래와 같은 경로에 있다.
-> CentOS 기준 : /etc/nginx/conf.d
-> Ubuntu 기준 : /etc/nginx/sites-available
docker로 띄운 NGINX는 CentOS와 경로가 같으니 CentOS 기준으로 들어가길 바란다.
vi test.conf를 사용해 테스트용 conf파일을 만든다.
server{
listen 80;
server_name localhost;
root /usr/share/nginx/html/test;
index index.html;
location /downloads { #웹 주소 뒤에 붙일 이름
alias /var/downloads/;
autoindex on;
access_log /var/log/nginx/down.access.log;
error_log /var/log/nginx/down.error_log;
charset utf-8;
}
}
이렇게 입력하고 저장한다.
4. nginx.conf 수정
-> /etc/nginx 경로에 있는 nginx.conf의 Include를 수정해야한다.
기존 nginx.conf의 include는
"include /etc/nginx/conf.d/*.conf;"로 되어 있을 것이다.
나는 이렇게 되어있으니 default.conf가 인식이 되어 명시적으로 바꿔주었다.(이렇게 해도되는건지는 모름....)
"include /etc/nginx/conf.d/test.conf;
5. nginx -t or sudo nginx -t 를 이용하여 구문 오류 확인

성공하면 이런 메세지가 나온다.
6. service nginx reload or sudo service nginx reload를 이용하여 재부팅
7. localhost:8989/downloads 에 접속하여 파일 존재 유무 확인
-> localhost:8989/downloads/{filename}를 이용하여 다운로드도 가능하다.
'운영 > Linux' 카테고리의 다른 글
| Mac에서 Window WSL 접속하기 (0) | 2023.02.06 |
|---|---|
| SFTP - 파일 업로드 및 다운로드 (For Mac) (0) | 2023.01.31 |