node.js - 仅当我使用 Nginx 和通配符添加端口号时,子域才有效
问题描述
我正在使用 nginx 创建一个 Web 服务器,我确实设法让一切正常工作,但我的服务器被摧毁了,所以我需要重新做一遍,现在我面临一个我没有遇到的问题。
我使用 Nodejs 并表达
我确实安装了通配符。
当我导航到主页时,一切都很好,它正在工作,但是当我转到任何其他 pagr 时,我必须添加 :3000 才能工作,否则我会被带到主页(如果我尝试子域) 如果我不得不说“example.com/page1”,就会得到 404。
假设我的域是 example.com
要访问 dom.example.com,我需要输入 dom.example.com:3000 否则我将被带到 example.com
这是我的配置文件:
server {
listen 80;
server_name www.example.com example.com *.example.com;
location / {
proxy_pass http://localhost:3000/;
}
}
和我的节点服务器:
const express = require('express');
const app = express();
var sub = require('wildcard-subdomains')
app.use(sub({
namespace: 's',
whitelist: ['www', 'app'],
}))
.get('/', (req, res) => {
res.send("Hello World!");
})
.get('/s/:p/', (req, res) => {
res.send(`sub domain`)
console.log('ooo')
})
const port = 3000;
const server = app.listen(port, () => {
console.log(`Listening on http://localhost:${port}`);
});
解决方案
推荐阅读
- java - 运行示例数据时 MaxEnt 出现问题
- javascript - 如何通过 Github API 创建树?
- ios15 - 导航栏 setBackgroundImage 在 iOS15 上不起作用
- ios - PHFetchRequest 返回零数据与图像的可选数据?
- photoshop - 如何使用扩展脚本在 Photoshop 中保存特定的图层集
- sql - 有人可以帮助我理解 Postgres 中的歧义吗?
- c# - 有没有办法使用 JetBrains Rider 更改 .editorconfig 中的命名设置
- scala - 线程“主”java.lang.NoClassDefFoundError 中的异常:com/fasterxml/jackson/databind/Module
- javascript - 将 JS 添加到 Bootstrap html 表时出现问题(通过基本的 jsDelivr CDN 链接) - 我做错了什么?
- c# - 如何在 C# 中使用 ComboBox 从另一个 DataGridView 的 sql 表中选择数据名称?