简体   繁体   中英

Node.js on port 80

I have an application in Node.js that runs on port 3010 (domain.com:3010). Is it possible to make it run on port 80 (domain.com) ?

I have a VPS server with CentOS. I searched a lot but nothing has worked.

You can create a virtual host as described on 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>

IMO it's better to use Nginx instead of Apache in front of Node.js. Configuration example (my /etc/nginx/conf.d/default.conf file)

    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;
        }


    }

您可以更改应用程序配置中的端口,或将端口配置为在路由器中根据需要进行响应。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM