IT

아파치 웹서버와 리버스 프록시로 Node.js 서버 연결

SOGNOD 2024. 6. 22. 00:35
반응형

아파치 서버와 node.js 서버 연동

홈페이지 서비스는 Apache 서버가 제공하고
동적인 콘텐츠 작업은 Node.js 서버가 제공하도록 서버 구성 (PHP 안녕~)

1. Apache 서버에 리버스 프록시 설정

<VirtualHost *:80>
    ServerName www.example.com

    ProxyPreserveHost On
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
</VirtualHost>

이 설정은 Apache 서버가 www.example.com에 대한 모든 요청을 localhost:3000에 있는 Node.js 서버로 전달하도록 합니다.  

2. Node.js 서버 포트 분리

Apache와 Node.js를 다른 포트에서 실행하여 각 서버가 독립적으로 동작하도록 할 수 있습니다. 예를 들어, Apache는 80번 포트에서, Node.js는 3000번 포트에서 동작하도록 설정할 수 있습니다. 이 경우, 특정 요청을 Node.js 서버로 리디렉션하는 방식으로 사용할 수 있습니다.

<VirtualHost *:80>
    ServerName www.example.com

    DocumentRoot /var/www/html
    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    ProxyPreserveHost On
    ProxyPass /api http://localhost:3000/
    ProxyPassReverse /api http://localhost:3000/
</VirtualHost>

이 설정은 Apache가 www.homepage.co.kr의 정적 파일을 제공하고, /api 경로에 대한 요청은 Node.js 서버로 전달합니다.

 

정리하면

 

  • Apache를 리버스 프록시로 설정하여 Node.js 서버로 요청을 전달할 수 있습니다.
  • 각 서버를 다른 포트에서 실행하여 독립적으로 동작하게 할 수 있습니다.
  • Apache를 사용하여 정적 파일을 서빙하고, Node.js는 동적 요청을 처리하게 할 수 있습니다.

 

 

반응형