Skip to Content
Suffering builds character

2. 실습 환경 세팅

테스트용 서버 구성

server_a.js
const http = require('http'); const port = 3001; const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); console.log("Server A"); res.end('Node.js Server A\n'); }); server.listen(port, () => { console.log(`Server A running on http://localhost:${port}\n`); });

설정 파일 내용 작성

nginx.conf
events {} http {     server {         listen 80;         location / {             proxy_pass 'http://localhost:3001/';         }     } }

→ 루트(/) 경로로 요청 시 3001 포트로 실행된 서버로 요청이 전달됨

설정 파일 문법 검증

terminal
nginx -t

해당 설정 파일로 nginx가 동작하도록 적용

terminal
nginx -s reload

요청 접근 테스트

curl localhost

Node.js Server A가 응답됨

Last updated on