打开conf目录里的nginx.conf 文件 –> 新增一段upstream
upstream nodejs{
server 127.0.0.1:3000; //你的Express项目端口
# server 127.0.0.1:3001;
keepalive 64;
}
-> 在后面的server{}里引用这里定义好的nodejs
完整的片段如下:
server {
listen 80;
server_name www.xxx.com xxx.com; //请求到80端口的host
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://nodejs;
}
}
重启nginx:nginx –s reload或者nginx –c conf/nginx.conf