코딩 외
[mac] Nginx 설치 및 리버스 프록시 세팅 (Reverse proxy)
포시
2023. 7. 18. 09:48
728x90
설치
brew install nginx
설치 확인
brew services list
세팅
cd /usr/local/etc/nginx
rm -rf nginx.conf
vi nginx.conf
nginx.conf.default 파일이 있기 때문에 그냥 편하게 지우고 다시 만들기
nginx.conf 파일 수정
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upstream backend {
server localhost:8080;
server localhost:8081;
}
server {
listen 80;
location / {
proxy_pass http://backend/;
}
}
}
localhost:80 접속 시 localhost:8080, localhost:8081을
Round Robin(default) 스케줄링 알고리즘을 통해 접속되게 세팅한 모습.
다른 블로그에서의 소개와 달리 worker_processes, events, include, default_type에 해당하는 부분 없이 실행할 경우
nginx 실행시에 이처럼 error 256으로 나온다.
한참 헤매다 nginx.conf.default 파일을 참고해서 위와같이 작성했더니 잘되었음
실행
brew services start nginx
명령어를 통해 실행 시 잘 started 상태로 올라온 것을 확인할 수 있다.
localhost:80 접속 시 localhost:8080, localhost:8081 둘 중 하나로 접속되는 것까지 확인
728x90