Node.js + Nginx - What now?

后端 未结 12 1622
抹茶落季
抹茶落季 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:56

    You can run nodejs using pm2 if you want to manage each microservice means and run it. Node will be running in a port right just configure that port in nginx(/etc/nginx/sites-enabled/domain.com)

    server{
        listen 80;
        server_name domain.com www.domain.com;
    
      location / {
         return 403;
      }
        location /url {
            proxy_pass http://localhost:51967/info;
        }
    }
    

    Check whether localhost is running or not by using ping.

    And

    Create one single Node.js server which handles all Node.js requests. This reads the requested files and evals their contents. So the files are interpreted on each request, but the server logic is much simpler.
    

    This is best and as you said easier too

提交回复
热议问题