Node.js + Nginx - What now?

后端 未结 12 1818
抹茶落季
抹茶落季 2020-11-22 00:26

I\'ve set up Node.js and Nginx on my server. Now I want to use it, but, before I start there are 2 questions:

  1. How should they work together? How should I handl
12条回答
  •  半阙折子戏
    2020-11-22 00:51

    You can also setup multiple domain with nginx, forwarding to multiple node.js processes.

    For example to achieve these:

    • domain1.com -> to Node.js process running locally http://127.0.0.1:4000
    • domain2.com -> to Node.js process running locally http://127.0.0.1:5000

    These ports (4000 and 5000) should be used to listen the app requests in your app code.

    /etc/nginx/sites-enabled/domain1

    server {
        listen 80;
        listen [::]:80;
        server_name domain1.com;
        access_log /var/log/nginx/domain1.access.log;
        location / {
            proxy_pass    http://127.0.0.1:4000/;
        }
    }
    

    In /etc/nginx/sites-enabled/domain2

    server {
        listen 80;
        listen [::]:80;
        server_name domain2.com;
        access_log /var/log/nginx/domain2.access.log;
        location / {
            proxy_pass    http://127.0.0.1:5000/;
        }
    }
    

提交回复
热议问题