configured a Nginx proxy server under windows, started a server service using node, and used a separate configuration file test.conf, but could not access it through the address test.com configured in test.conf?
related codes
test.conf:
server {
listen 80;
server_name www.test.com;
location /
{
proxy_pass http://127.0.0.1:8888;
}
}
The configuration of test.conf is introduced in nginx.conf:
include servers/*.conf;
server.js:
const http = require("http")
const fs = require("fs")
const zlib = require("zlib")
http.createServer(function (request, response) {
console.log("request come", request.url)
const html = fs.readFileSync("test.html")
response.writeHead(200, {
"Content-Type": "text/html",
// "X-Content-Options": "nosniff"
"Content-Encoding": "gzip"
})
response.end(zlib.gzipSync(html))
}).listen(8888)
console.log("server listening on 8888")
test.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="/form" id="form" enctype="application/x-www-form-urlencoded">
<input type="text" name="name">
<input type="password" name="password">
<input type="file" name="file">
<input type="submit">
</form>
<script>
var form = document.getElementById("form")
form.addEventListener("submit", function (e) {
e.preventDefault()
var formData = new FormData(form)
fetch("/form", {
method: "POST",
body: formData
})
})
</script>
</body>
</html>
server service is started. Running result:
test.com127.0.0.1:8888