node.js - Nginx proxy_reverse 和节点服务器。您在哪里看到来自上游 NODE 服务器的控制台日志 OUTPUT?
问题描述
我来自 Windows 服务器世界。第一次使用 Nginx,到目前为止,它令人印象深刻,但我有一个问题,这就是我在这里的原因;)
我有 Ubuntu 20.04、Nginx 并部署了 expressjs 应用程序(节点),按照那里的所有教程设置 Nginx 和 proxy_reverse 服务器。它有效,我能够查看并运行/与我的 expressjs 应用程序路由(家庭、登录、注册......等)进行交互
我唯一的问题是我看不到我放置在路由(我的节点服务器)中的 console.log 的结果获取路由示例:
app.get('/', function (req, res) {
console.log("db is connected, user is loggedin and we're ready to
go....wait...another issue with Nginx I need to research and I can't
find in the docs")
res.send('hello world')
})
如果我的节点服务器位于 Nginx 服务器之后,我如何查看该路由的结果?有没有办法让 Nginx 向我(管理员)显示这些日志?
有数以万亿计的教程介绍如何将 nginx 添加为代理,但其中没有一个讨论这个重要问题。如果您有我可以阅读的链接,或者您对 Nginx proxy_reverse 日志操作有足够的经验,请详细解释或用代码向我展示您如何从 expressjs 路由查看 console.log。
所以,我的问题是如何在上面的输出示例中看到 console.log ?是 Nginx 参数吗,这是我的服务器设置 /etc/nginx/sites-available/default (我删除了不相关的部分):
server {
listen 80 default_server;
listen [::]:80 default_server;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
在 location/server 的上下文中是否有一个指令,我需要允许将日志从 node/expressjs 服务器传递到 nginx shell 或任何地方以查看 node/express 路由发生了什么?它是否在我需要注意的某个地方的 nginx 日志中?
解决方案
对于从这个堆栈开始的任何人,当您进入您的应用程序目录时,pm2 日志会将日志打印到您的控制台。
my_app_directory pm2 logs
推荐阅读
- angular - 如何保护子路由并在子路由之间导航?
- python - 无和逻辑操作和/或
- react-native - 两个平面列表合而为一 Reat Native
- orbeon - orbeon 表单数据未存储在 mysql 数据库中
- spring-boot - Spring Boot API端点问题
- php - mysql查询多次插入数据
- stored-procedures - MULE 4:存储过程:执行 mule 流以运行存储过程返回“索引 1 超出范围”
- c# - 通过托管标识 c# 访问 AzureBlobStorage
- ios - @react-native-firebase/messaging : TypeError: (0 , _messaging.default)(...).registerForRemoteNotifications 不是函数
- python - 动态创建可以从任何地方导入的不可变常量?