사용환경 : Ubunut 20.0.4 LTS, Apache2.x, Node.js, Javascript
Apache설정 변경
# /etc/apache2/sites-available/000-default.conf 내용 추가
<VirtualHost *:80>
ServerName example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /nodejs>
ProxyPass http://localhost:3000
ProxyPassReverse http://localhost:3000
</Location>
<Directory "/var/www/example.com/html">
AllowOverride All
</Directory>
</VirtualHost>
3000포트로 허용함을 설정
$ sudo service apache2 restart
아파치 서버 재구동
# /var/www/html/nodejs/hello.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World! Node.js is working correctly.\n');
}).listen(3000);
console.log('Server running at http://127.0.0.1:3000/');
console.log('It is running now...');
마찬가지로 3000포트 연결 설정
hello.js 파일 실행
$ node /var/www/html/nodejs/hello.js
http://example.com:8080/node.js/
접속
일단 서버 내에서 8080포트로 접속하여 3000포트의 Websocket communication 로그 출력이 완료되었다.
Apache + Node.js + socket.io
코드 이그나이터에서 웹소켓을 돌리는데 드디어 성공! 꽤나 뿌듯하다. 스택 오버플로우와 국내 블로그의 도움을 많이 받았다. 순서대로 오늘 한 일에 대해서 나열해보자면 1. 공유기 포트포워딩
blog.rgbplace.com
Set Up a Node.js App for a Website With Apache on Ubuntu 16.04
This tutorial will explain how to set up a Cloud Server running Ubuntu 16.04 so that Node.js scripts run as a service, and configure the Apache server to make the script accessible from the web.
www.ionos.com
Behind a reverse proxy | Socket.IO
You will find below the configuration needed for deploying a Socket.IO server behind a reverse-proxy solution, such as:
socket.io
반응형