本地安装nginx
下载链接
http://nginx.org/en/download....
nginx结构
运行nginx
打开localhost:80
设置代理
server.js
const http = require('http');
const fs = require('fs');
http.createServer(function(req, res) {
console.log('request come', req.headers.host);
if (req.url === '/') {
const html = fs.readFileSync('test.html', 'utf8');
res.writeHead(200, {
"Content-Type": "text/html",
})
res.end(html)
}
}).listen(8888)
console.log('server start at port 8888')
D:nginxnginx-1.15.6confnginx.conf
增加一个server
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://127.0.0.1:8888;
}
}
重启运行nginx
http://localhost:8888/
test.com
nginx子文件配置方式
新建conf.d文件夹和test.conf文件
修改nginx.conf
include conf.d/*.conf;
conf.d/test.conf
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
}
}
设置host
server.js打印
修改nginx.conf
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
}
}
server.js打印
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。