
저는 LAMP 세계에서 왔기 때문에 웹 서버에서 ExpressJS 애플리케이션을 제공하는 방법에 대해 약간 혼란스럽습니다.
다양한 디렉토리를 가리키고 다양한 도메인 이름을 지정하는 여러 Apache 가상 호스트가 있습니다. 그들은 모두 /etc/apache2/sites-available/
내 Ubuntu에 구성 파일을 가지고 있습니다.
/var/www/
어쨌든, 저는 node를 사용하여 ExpressJS 인스턴스를 설치했는데, 이는 제 다른 웹(Apache) 항목과 함께 내 디렉토리의 디렉토리에 있습니다 .
별도의 작업을 수행하지 않고도 특정 도메인 이름으로 서비스를 제공하려면 어떻게 해야 합니까 IP:3000
(방화벽 때문에 작동하지도 않습니다). 나는 이것을 본다:Apache HTTPD: 프록시 및 디렉터리 별칭이 있는 가상 호스트에 대한 URL 확인, 하지만 다른 곳에서 읽었기 때문에 노드용 Apache 호스트가 성능을 방해하므로 피하고 싶기 때문에 그것이 맞는지 잘 모르겠습니다. 여기서 가장 좋은 답변을 찾고 있습니다.
성능에 미치는 영향을 최소화하면서 포트 80을 사용하고 특정 도메인에 매핑되어야 합니다. 또한 노드 파일에서 정확히 무엇을 가리켜야 할지 잘 모르겠습니다. /var/www/nodeapp/node_modules/express/index.js
파일을 추측하고 있습니까?
귀하의 은혜로운 도움에 감사드립니다!
답변1
Michael Hampton 링크에 감사드립니다. 다음은 향후 참조를 위한 완전/수정된 답변입니다.
Apache VirtualHost/구성 파일:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyPass "/" "http://localhost:3000"
ProxyPassReverse "/"= "http://localhost:3000"
</VirtualHost>
메모:위 작업을 수행하려면 Apache mod_proxy
패키지를 설치하거나 Apache 설명서를 참조하거나 다음을 수행해야 합니다.
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_ajp
a2enmod rewrite
a2enmod deflate
a2enmod headers
a2enmod proxy_balancer
a2enmod proxy_connect
a2enmod proxy_html
3000
구성 파일에 있는 내용은 내 Node 앱이 실행되고 있기 때문입니다. 여기를 참조하세요.
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
* index.js
*/
'use strict';
var express = require('./lib/express');
var http = require('http');
var app = express();
var server = http.createServer(app);
app.get('/', function(req, res) {
res.send("Hello World!");
});
server.listen(3000, 'localhost');
server.on('listening', function() {
console.log('Express server started on port %s at %s', server.address().port, server.address().address);
});
실행하려면 다음을 수행하세요.node index.js
해당 명령을 종료한 후에도 계속 실행하려면 &
다음과 같이 를 추가하세요.
node index.js &
^ Unix 세션이 활성화된 동안에만 실행을 유지합니다. 예를 들어 SSH 클라이언트 노드를 닫으면 &
.
영구적으로 실행하려면 여기를 보십시오.https://stackoverflow.com/questions/12701259/how-to-make-a-node-js-application-run-permanently