admin管理员组文章数量:1325594
I just installed Node.js, got it working for a while, then tried to run a standard Hello World program.
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
I then launched the domain I set up for node, - I successfully got it to print Hello World
when I did the same on my domain last week. However now, I keep getting 503 Service Temporarily Unavailable error.
This happened last week too, after I closed the server, edited the code, then reran the server, it would 503 unless I waited a few minutes before running again. However, waiting makes no difference this time.
Apache config for domain:
<VirtualHost *:80>
ServerAdmin zadmin@localhost
DocumentRoot "/var/zpanel/hostdata/zadmin/public_html/node"
ServerName node.foobar
ProxyRequests on
ProxyPass / http://localhost:3102/
# Custom settings are loaded below this line (if any exist)
</VirtualHost>
I just installed Node.js, got it working for a while, then tried to run a standard Hello World program.
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
I then launched the domain I set up for node, http://node.foobar. - I successfully got it to print Hello World
when I did the same on my domain last week. However now, I keep getting 503 Service Temporarily Unavailable error.
This happened last week too, after I closed the server, edited the code, then reran the server, it would 503 unless I waited a few minutes before running again. However, waiting makes no difference this time.
Apache config for domain:
<VirtualHost *:80>
ServerAdmin zadmin@localhost
DocumentRoot "/var/zpanel/hostdata/zadmin/public_html/node"
ServerName node.foobar.
ProxyRequests on
ProxyPass / http://localhost:3102/
# Custom settings are loaded below this line (if any exist)
</VirtualHost>
Share
Improve this question
edited Jun 15, 2016 at 10:40
unicornication
asked Jun 15, 2016 at 10:29
unicornicationunicornication
6272 gold badges9 silver badges26 bronze badges
1
- I know this has been solved before, whoever one root cause of 503s is also the NodeJS code itself. If there is an error in the Node.JS code, your webpage will happily throw a 503 error. **This is just for any passers-by who encountered this issue with the same code, but have a different problem. – TORUS Commented Jul 18, 2020 at 6:51
2 Answers
Reset to default 1How do you set up the domain?
Did you use another HTTP server as a proxy?
Please check if node is running, and if yes check your HTTP server is too.
Maybe your node crashed or is just not running.
Another test is to connect your node directly:
http://127.0.0.1:8081/
I've been having the same issue. We're using the (no-longer supported) "node-ews" library to load emails/attachments from our Exchange server, and it regularly throws 503 errors.
My colleagues have told me, meh, this is expected behavior with micro-services (really?) and that I just need to use a library to add some resilience, eg.
https://github./resilient-http/resilient.js/#how-does-it-work
My solution was to actually call the Exchange endpoint, and if it's a 503 error, log it (and show how many retries we've done), wait for a second, then try again. This did actually solve the issue for me.
var EXCHANGE_SLEEP_TIME = 1000;
var EXCHANGE_MAX_RETRIES = 20;
var retryNumber = 0;
var bSuccess = false;
do {
// Attempt to update the categories on this email ("UpdateItem" function), but be careful of 503 errors.
await ews.run(ewsUpdateFunction, updateArgs)
.then(result => {
// Do something with the result
bSuccess = true;
})
.catch(err => {
var statusCode = (err.response) == null ? -1 : err.response.statusCode;
var errorString = `setEmailCategory, attempt: ${++retryNumber}, statusCode: ${statusCode}`;
if (statusCode != 503)
errorString += `, exception: ${JSON.stringify(err)}`;
console.log(errorString);
this.sleep(EXCHANGE_SLEEP_TIME);
});
} while (retryNumber < EXCHANGE_MAX_RETRIES && !bSuccess);
. . .
public sleep(ms: number) {
// Dumb function, to make the code go to sleep for XX milliseconds
return new Promise( resolve => setTimeout(resolve, ms) );
}
Yeah, it's ugly, but frighteningly, it works quite well.
Obviously, the "real" version logs the messages to a Logging service, rather than the console.
本文标签: javascriptNodejs consistently giving 503 errorStack Overflow
版权声明:本文标题:javascript - Node.js consistently giving 503 error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742189865a2430010.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论