[英]Node.JS + Apache - Cannot GET
我正在尝试同时使用 Apache 和 Node.JS,但它没有按预期工作。
// Apache
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.com
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
对于我的 server.js
// Node
const express = require ('express');
const server = express();
server.get('/', function(req,res){
return res.send('The code works fine here');
});
server.get('/foo', function(req,res){
return res.send('Here => Cannot GET /foo');
});
server.get('/foo2', function(req,res){
return res.send('Here too => Cannot GET /foo2');
});
server.listen(3000, function() {
console.log('server is only working for "/" ')
});
mydomain.com
工作完美,但我找不到让所有其他子域mydomain.com/*
工作的方法。 有人能给我一盏灯吗?
您可以使用Apache 反向代理
将此配置添加到您的 apache conf。
ProxyPass "/nodeapp" "http://localhost:8443"
您可以通过http://www.example.com/nodeapp访问节点应用程序
反向代理是一种代理服务器,它代表客户端从服务器检索资源。 然后,这些资源将返回给客户端,就好像它们来自 Web 服务器本身一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.