node结合nginx绑定域名
- node开启服务
-
const express = require('express'); const app = express(); const path = require('path'); //使用静态资源 app.use(express.static(path.join(__dirname, 'dist'))); //监听端口号 app.listen(3000, () => { console.log('服务启动成功') }); - nginx配置
-
#配置nodejs转发域名 upstream nodejs { server 127.0.0.1:3000; keepalive 64; } server { listen 80; server_name www.wjx.test; #charset koi8-r; #access_log logs/host.access.log main; location / { # root html; # index index.html index.htm; proxy_pass http://127.0.0.1:3000; } }
- 配置hosts文件
- 路径:C:\Windows\System32\drivers\etc
- 代码:127.0.0.1 www.wjx.test
- nginx常见命令
- start nginx 开启nginx
- nginx -s reload 重启nginx
- nginx -s stop 停止nginx

浙公网安备 33010602011771号