端口80上的Node.js

端口80上的Node.js

问题描述:

我在端口3010(domain.com:3010)上运行的Node.js中有一个应用程序。是否有可能使其在端口80(domain.com)上运行?端口80上的Node.js

我有一个CentOS的VPS服务器。 我搜索了很多,但没有任何工作。

+0

你可以访问应用程序的源代码? – etienne 2013-02-19 17:56:33

+0

是的,我有,但我不能更改为端口80,因为它被Apache使用 – 2013-02-19 18:52:32

+2

然后有Apache重定向请求80到3010.你肯定不能有几个服务器在同一个端口上侦听! – etienne 2013-02-19 18:58:54

this article

<VirtualHost *:80> 
    ServerName node.mydomain.com 
    ProxyRequests off 
    <Proxy *> 
     Order deny,allow 
     Allow from all 
    </Proxy> 
    <Location /> 
     ProxyPass http://localhost:3010/ 
     ProxyPassReverse http://localhost:3010/ 
    </Location> 
</VirtualHost> 
+0

谢谢!这是我正在寻找的。 – 2013-02-21 14:19:46

+0

嘿!,这真棒我在5分钟内工作,但POST请求不起作用,这是只为GET或我错过了什么? – pjnovas 2013-03-22 23:49:03

您可以更改应用配置中的端口或配置端口以在路由器中进行响应。

描述您可以创建一个虚拟主机IMO这是更好地使用Nginx的,而不是在阿帕奇的Node.js的前面 配置示例(我/etc/nginx/conf.d/default.conf文件)

upstream my-node-app { 
     server 127.0.0.1:3000; 
    } 

    server { 
     listen  80 default_server; 
     #server_name _; 
     server_name www.domain.com domain.com; 


     access_log /var/log/nginx.access.log main; 

     location/{ 
      #root /usr/share/nginx/html; 
      #index index.html index.htm; 
      proxy_pass http://127.0.0.1:3000/; 
     } 

     error_page 404    /404.html; 
     location = /404.html { 
      root /usr/share/nginx/html; 
     } 

     # redirect server error pages to the static page /50x.html 
     # 
     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
      root /usr/share/nginx/html; 
     } 


    }