- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是服务器环境中的 Nodejs 新手,并试图弄清楚如何使其与我在 digital ocean 服务器上运行的所有其他东西结合使用。
我成功地在 digital ocean 的子域上设置了一个沙箱环境,其中我有一个 Express 服务器监听来自端口 3000 的请求。然后,我可以从端口 3000 上的 Web 浏览器发出 ajax GET 请求到 Node 服务器,并检索响应。
但是,现在我正在尝试将该沙箱环境实现到一个新的子域中,我在其中运行 craft PHP CMS。它运行默认端口 80。所以我希望我的 Node 服务器能够监听来自端口 80 的请求。但在此之前我可以说:
app.listen(3000, function () {
console.log('listening')
})
如果我尝试从端口 3000 运行 craft,则会引发 URL 路由错误:无法获取 [url_segments]
因为它旨在查找来自端口 80(默认 Web 端口)的请求。如果我将 Express 服务器更改为监听端口 80,则会出现错误,指出该地址正在使用中。
> node app.js:
Error: listen EADDRINUSE :::80
如何让 app.js
只监听 digital ocean 服务器上的默认公共(public) html 端口,而不出现此 EADDRINUSE 错误?我希望人们访问我的子域:
http://subdomain.domain.com/episodes/episode-2
并让它能够通过 AJAX 向我的 Express 服务器进行调用:
var urlParams = new URLSearchParams(window.location.search);
var startDate = urlParams.get('start');
var endDate = urlParams.get('end');
var urlWithParams = "/list?start=" + startDate + "&end=" + endDate;
$.ajax({
method: "GET",
url: urlWithParams,
}).done(function (data) {
//do stuff
})
我的 express 服务器上的列表函数类似于:
let app = express()
app.get('/list', (request, response) => {
//DO STUFF
}
我在使用 Ubuntu 14.04 和 Apache2 的 digital ocean 服务器上
最佳答案
您需要使用代理。
nginx 示例:
server {
listen 80;
server_name subdomain.domain.com
location / {
proxy_pass http://localhost:3000;
}
}
Apache :
<VirtualHost *:*>
ProxyPass / http://0.0.0.0:3000/
ServerName localhost
</VirtualHost>
关于jquery - digital ocean 服务器上的 apache2/nodejs/express - 如何在没有地址使用错误的情况下监听公共(public)端口(80),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48029292/
我是一名优秀的程序员,十分优秀!