가볍고 높은 성능을 보이는 오픈소스 웹 서버 소프트웨어
Tocmat과 Jetty는 WAS이고, NginX는 웹 서버다.
NginX는 정적 리소스를 빠르게 응답하기 위한 웹 서버로 사용할 수 있다.
우선 NGINX를 다운로드 받는다.
그리고 NGINX를 실행한다.
NGINX 설정 파일 nginx.conf 파일을 수정한다.
server {
listen 80;
...
location / {
...
proxy_pass http://localhost:8080; # 요청을 8080 포트로 넘깁니다.
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
NGINX 설정을 바꾸었으면 재시작 해야한다.
스프링 부트 프로젝트도 실행해해준다.
localhost:80 으로 접속하면 스프링 부트 프로젝트 랜딩 페이지를 확인할 수 있다.
스프링 부트 프로젝트를 8080, 8081 포트로 실행하자
nginx.conf 파일을 수정한다.
backend
라는 서버 그룹을 만들고 그룹 자체로 전덜하는 구조로 변경
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream backend {
server localhost:8080;
server localhost:8081;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://backend;
}