nginx란 무엇일까?
경량 웹서버이다.
클라이언트로부터 요청을 받았을때 요청에 맞는 정적파일을 응답해주는 http 웹서버로 활용된다.
Reverse Proxy Server로 활용하여 WAS 서버의 부하를 줄일 수 있는 로드밸런서로도 사용된다.
일단 ubuntu18.04에 최신버전의 nginx를 설치해야한다.
최신버전 nginx설치하기
nginx.list 파일을 만든후에
vi /etc/apt/sources.list.d/nginx.list
아래의 내용을 입력해준다.
deb https://nginx.org/packages/ubuntu/ bionic nginx
deb-src https://nginx.org/packages/ubuntu/ bionic nginx
apt 업데이트 및 설치
$ apt-get update
$ apt-get install nginx
NO_PUBKEY $key 에러가 발생하면
W: GPG error: https://nginx.org/packages/ubuntu xenial Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62
터미널에 나온 키를 아래의 $key에 넣어준다.
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key
$ sudo apt-get update $ sudo apt-get install nginx
이제 nginx를 설치 하면 최신버전으로 설치 된다.
sudo apt-get install nginx
sudo service nginx start를 하게 되면 정상적으로 실행된다!!
이제 nginx를 이용해서 포트포워딩을 해보겠습니다!!
vi /etc/nginx/nginx.conf 명령어로 nginx.conf 파일에 접속
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
위와 같은 형식의 파일에서 include /etc/nginx/comf.d/*.conf 를 보면 해당 위치에 conf 확장자를 가진 파일을 모두 include한다는 의미이다.
그렇다면 해당 폴더로 이동해보자
cd /etc/nginx/conf.d
이동해서 vi default.conf를 통해 파일을 열어보면
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
#root /root/javascript-p2-airbnb/dist;
#index index.html index.htm;
proxy_pass http://localhost:8080;
}
이런식으로 구성되어 있을 것이다.
이 부분의 내용은 80포트로 들어온 내용을 8080 포트로 포워딩하라는 의미이다.(포트 넘버는 자신에 맞게 바꾼다.)
아직은 도메인을 만들지 않아 localhost 이다
proxy_pass를 추가해주는 것이 포인트!!
끝!
반응형
SMALL
'웹 프로그래밍 > BackEnd' 카테고리의 다른 글
[Backend] ORM과 Sequelize (0) | 2021.09.29 |
---|---|
로그인 - 쿠키와 세션 (0) | 2021.09.29 |
[Database] ERD란 무엇일까? (0) | 2021.09.27 |
[express, nodejs] res.send() VS res.json() 그리고 res.end() (0) | 2021.09.16 |
REST API(그런 REST API로 괜찮은가?) (0) | 2021.09.13 |