【发布时间】:2019-10-20 03:57:48
【问题描述】:
我对 node.js 很陌生,对服务器了解不多。
我制作了一个节点应用程序并使用node server.js & 在我的服务器中启动它(他在 php 中有一些其他网站,因此它需要与 apache 一起使用)。
它运行良好,并且一直运行到第二天,当我收到 503 错误时。再次使用 ssh 进入我的服务器并发现它无法正常工作,所以我再次开始使用运行 nodemon server.js & 的 nodemon。
同样的事情,几个小时后我又遇到了 503 错误。
我遵循的步骤:
1. 在 /var/www/
中创建网站文件夹
2. 在 /etc/apache2/sites-available/ 中创建网站配置(mysite.com.conf 文件如下所示)
3. 使用e2ensite启用网站
5. 为 SLL 证书运行 cerbot
6. 重新加载 apache
7. 使用nodemon server.js > log.out & 启动应用程序
我创建了 mysite.com.conf,如下所示:
<VirtualHost *:80>
ServerAdmin user@MAINDOMAIN.com
ServerName MYSITE.MAINDOMAIN.com
ServerAlias www.MYSITE.MAINDOMAIN.com
DocumentRoot /var/www/MYSITE.MAINDOMAIN.com/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/MYSITE.MAINDOMAIN.com/public">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://127.0.0.1:7000/
ProxyPassReverse / http://127.0.0.1:7000/
RewriteEngine on
RewriteCond %{SERVER_NAME} =MYSITE.MAINDOMAIN.COM [OR]
RewriteCond %{SERVER_NAME} =www.MYSITE.MAINDOMAIN.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI}
[END,NE,R=permanent]
</VirtualHost>
我的 server.js 文件如下所示:
const express = require('express')
const mysql = require('mysql')
const app = express()
//mysql database connection here
//some app.get() here to render pages
const server = app.listen(7000, () => {
console.log('Express running on port ${server.address().port}');
});
我在 log.out 中收到的最后一条消息是 app crashed - waiting for file changes before starting。
我怎样才能保持这个运行?我是不是做错了什么?
【问题讨论】:
-
谢谢,我会永远尝试使用
-
另一个要查看的选项是 pm2
标签: node.js express http-status-code-503