Node.js + Nginx - What now?

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

    Node.js with Nginx configuration.

    $ sudo nano /etc/nginx/sites-available/subdomain.your_domain.com
    

    add the following configuration so that Nginx acting as a proxy redirect to port 3000 traffic from the server when we come from “subdomain.your_domain.com”

    upstream subdomain.your_domain.com {
      server 127.0.0.1:3000;
    }
    server {
      listen 80;
      listen [::]:80;
      server_name subdomain.your_domain.com;
      access_log /var/log/nginx/subdomain.your_domain.access.log;
      error_log /var/log/nginx/subdomain.your_domain.error.log debug;
      location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://subdomain.your_domain.com;
        proxy_redirect off;
      }
    }
    

提交回复
热议问题