When serving a Go web server via an Nginx proxy, is it possible to have Nginx log requests and errors?

agolangf · 2017-04-06 21:00:08 · 612 次点击    
这是一个分享于 2017-04-06 21:00:08 的资源,其中的信息可能已经有所发展或是发生改变。

I have the following basic Nginx configuration that proxies requests through to my Go app, which runs on port 8080:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    server_name 192.168.50.50;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8080;
    }
}

I came across this configuration by doing some googling, however it doesn't seem to be logging any access or errors. Am I doing something wrong?


评论:

the_jester:

Your question has essentially nothing to do with Go, and is better restated: "What are the logging capabilities of Nginx?".

The answer is - Nginx can log just fine, but keep in mind its "error log" and "access log" are for its errors and access, not errors that may occur within your go code.

See the basic on Nginx logging here.

mrfrobozz:

You should be letting nginx log it's errors and have your go app logging it's own errors to its own log files.

nicklaw5:

It seems to be working fine now. Thanks.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

612 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传