Notice
Recent Posts
Recent Comments
송민준의 개발노트
Nginx 설치 본문
Nginx란?
- 가볍고 높은 성능을 가진 웹 서버이다.
- HTTP Server로 활용되며 정적 파일들을 처리하기 위해 사용된다.
- Reverse Proxy Server로 활용되며 특정 도메인, IP, 포트 등으로 들어온 것을 다른 곳으로 라우팅하며 로드밸런싱의 역할이 가능하다.
Nginx와 Apache의 차이점
Nginx는 Event Driven 방식으로 작동하고, Apache는 쓰레드 / 프로세스 기반으로 작동한다.
Event Driven
- 서버로 들어오는 여러 개의 커넥션을 Event-Handler를 통해 비동기 방식으로 처리한다.
- 이러한 방식으로 인해 적은 메로리로 운영 가능
- 싱글 스레드, 프로세스로 작동한다.
Thread / Process
- 클라이언트의 각 요청마다 Thread 자원이 1:1 할당된다.
- 다양한 모듈을 제공하며 확장성이 좋다.
설치 방법
sudo apt-get install nginx
기본적인 서버 리스너 양식( http 안에 넣어야한다 )
server {
// 특정 포트번호 리스너
listen 포트번호;
// 요청하는 도메인이나 ip
server_name 진입도메인,ip;
// https가 아닐경우 https로 리다이렉트
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
// url 세팅 파일 include
include /home/ubuntu/service_url.inc;
location / {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
// 지정한 url로 보냄
proxy_pass $service_url;
}
}
vim /home/ubuntu/service_url.inc
# service_url.inc
set $service_url http://127.0.0.1:8081;
세팅 후 nginx 재가동
systemctl restart nginx # nginx 재시작
systemctl start nginx # nginx 시작
systemctl stop nginx # nginx 중지
systemctl reload nginx # nginx 설정 리로드
Nginx 특정 url에서 라우팅
# image라는 경로로 왔을때 라우팅
location /image/ {
# 유효성 체크
rewrite ^/image/(.*)$ /$1 break;
proxy_pass 라우팅하고자 하는 도메인;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarede_for;
}
참고블로그
https://phsun102.tistory.com/45
'인프라 > ubuntu' 카테고리의 다른 글
ubuntu 가상머신에 설치하기(16.04) (0) | 2020.02.12 |
---|---|
VMnet8 IP주소 설정 (0) | 2020.02.11 |