<p>I have the following basic Nginx configuration that proxies requests through to my Go app, which runs on port 8080:</p>
<pre><code>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;
}
}
</code></pre>
<p>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?</p>
<hr/>**评论:**<br/><br/>the_jester: <pre><p>Your question has essentially nothing to do with Go, and is better restated: "What are the logging capabilities of Nginx?".</p>
<p>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.</p>
<p>See the basic on <a href="https://www.nginx.com/resources/admin-guide/logging-and-monitoring/" rel="nofollow">Nginx logging here</a>.</p></pre>mrfrobozz: <pre><p>You should be letting nginx log it's errors and have your go app logging it's own errors to its own log files.</p></pre>nicklaw5: <pre><p>It seems to be working fine now. Thanks.</p></pre>
When serving a Go web server via an Nginx proxy, is it possible to have Nginx log requests and errors?
agolangf · · 470 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传