Marcos Aguayo
Marcos Aguayo

Reputation: 7170

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.

Upvotes: 0

Views: 370

Answers (3)

Roman Podlinov
Roman Podlinov

Reputation: 24944

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


    }

Upvotes: 1

etienne
etienne

Reputation: 3206

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>

Upvotes: 1

gustavohenke
gustavohenke

Reputation: 41440

You may change the port in the app configurations or configure the ports to respond as you want in your router.

Upvotes: 0

Related Questions