node开启本地服务
app.js
const express = require('express');
const app = express()
app.get("/api",(req,res)=>{
res.send({text:"/api response"})
})
app.get("/api/first",(req,res)=>{
res.send({text:"/api/first"})
})
app.listen(3002,()=>{
console.log("服务器启动成功")
})
运行 cmd 窗口 node app.js
浏览器访问 http://127.0.0.1:3000
此时本地服务器已开启,下一步配置nginx代理
nginx配置
nginx 安装目录下的 conf/nginx.conf 文件
配置server部分
server {
listen 8090; // 监听的端口号
server_name localhost; // 主机名称 可以用域名 或者IP地址
location /{
proxy_pass http://127.0.0.1:3002;
}
}
启动nginx
在nginx目录下 cmd 窗口 nginx
或者重新加载配置nginx -s reload
浏览器访问 http://localhost:8090
浏览器访问 http://localhost:8090/api