有一些开发主机,我们正在尝试运行Apache / PHP和Node.js。 对于运行在本地端口上的节点服务,理想的简单ProxyPass应该可以工作,但由于某种原因,我需要提供本地networkingIP,localhost会给出503错误。
$ cat nodeproxy.conf
<Directory /public/np1/site> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> <VirtualHost *:80> ServerName np1.local.zaptech.org DocumentRoot /public/np1/site ProxyRequests on # ProxyPass /np1/ http://localhost:1337/ <- doesn't work, 503 error # ProxyPass /np1/ http://127.0.0.1:1337/ <- doesn't work, 503 error ProxyPass /np1/ http://10.10.10.76:1337/ </VirtualHost>
$ cat sysd
[Unit] Description=Node.js Example Server [Service] ExecStart=/bin/node /home/rickatech/node/example.js Restart=always RestartSec=10 # Restart service after 10 seconds if node service crashes StandardOutput=syslog # Output to syslog StandardError=syslog # Output to syslog SyslogIdentifier=nodejs-ricktest User=rickatech Environment=NODE_ENV=production PORT=1337 [Install] WantedBy=multi-user.target
简单的答案是在端口1337上运行的服务只绑定到主IP地址,而不是本地主机,你可以使用netstat,lsof或类似的东西来查找。
我不知道node.js,但我敢肯定,一个快速search会发现post告诉你如何使node.js绑定到本地主机,如果不是。
一个简单的说明,您应该始终匹配您的ProxyPass(和ProxyPassReverse)指令中的尾部斜线。 所以例如
ProxyPass / np1 / http:// localhost:1337 / 要么 ProxyPass / np1 http:// localhost:1337
代替
ProxyPass / np1 http://10.10.10.76:1337/ 要么 ProxyPass / np1 / http://10.10.10.76:1337
通常情况下,除非有特定的原因,否则两者都应该有斜线。
啊,这个兔子的洞更深一点
$ cat example.js
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); }).listen(1337, "10.10.10.76"); // change this to 127.0.0.1 !
端口是在JavaScript中,不知道为什么sysd需要PORT指令。