# Nginx not logging to socket

**URL:** <https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393>\
**Category:** NGINX\
**Created:** [June 21, 2015, 2:19pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393 "2015-06-21T14:19:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [June 21, 2015, 2:19pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/1 "2015-06-21T14:19:32Z")

</div>

Hallo!

Using rsyslog I have set up a logging socket and confirmed that its  
working  
by piping in some stuff to “logger -u /dev/log”  
nginx/1.8.0 does not seem to be dumping in logs however. The nginx  
config  
is below…

I’m probably doing something dumb. This is the first time I set this up.

Cheers,

Andrew

# For more information on configuration, see:

# \* Official English Documentation: [nginx documentation](http://nginx.org/en/docs/)

# \* Official Russian Documentation: [nginx: документация](http://nginx.org/ru/docs/)

user nginx;

worker\_processes 4;

#error\_log /var/log/nginx/error.log debug;

error\_log syslog:server=unix:/dev/log debug;

pid /run/nginx.pid;

events {

```
worker_connections 1024;

```

}

http {

# Log to Rsyslog socket

log\_format syslog ‘$remote\_addr $host:$server\_port “$request” $status  
$body\_bytes\_sent “$http\_referer” “$http\_user\_agent”’;

access\_log syslog:server=unix:/dev/log syslog;

# log\_format main '$remote\_addr - $remote\_user [$time\_local]

“$request” ’

# '$status $body\_bytes\_sent “$http\_referer” ’

# ‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

# 

# access\_log /var/log/nginx/access.log main;

```
sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 2048;

include /etc/nginx/mime.types;

default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d 

```

directory.

```
# See http://nginx.org/en/docs/ngx_core_module.html#include

# for more information.

include /etc/nginx/conf.d/*.conf;

```

}

–  
Otter Networks UG  
[http://otternetworks.de](http://otternetworks.de)  
fon: +49 30 54 88 5197  
Gotenstraße 17  
10829 Berlin

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 24, 2015, 12:13pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/2 "2015-06-24T12:13:32Z")

</div>

Hello,

On Sun, Jun 21, 2015 at 8:19 AM, Andrew Holway  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hallo!
> 
> Using rsyslog I have set up a logging socket and confirmed that its working  
> by piping in some stuff to “logger -u /dev/log”  
> nginx/1.8.0 does not seem to be dumping in logs however. The nginx config is  
> below..

Any luck? I’m seeing the same problem on 1.7.12.

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 24, 2015, 1:03pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/3 "2015-06-24T13:03:46Z")

</div>

On Wed, Jun 24, 2015 at 06:12:49AM -0400, Danomi Czaski wrote:

> Any luck? I’m seeing the same problem on 1.7.12.

do you see some errors in the local error log? If nginx is unable to  
send data to socket for some reasons (check socket permissions, selinux  
and similar), you will see errors in the local log file.

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 24, 2015, 2:32pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/4 "2015-06-24T14:32:00Z")

</div>

On Wed, Jun 24, 2015 at 7:03 AM, Vladimir H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > below..
> > 
> > Any luck? I’m seeing the same problem on 1.7.12.
> 
> do you see some errors in the local error log? If nginx is unable to  
> send data to socket for some reasons (check socket permissions, selinux  
> and similar), you will see errors in the local log file.

My config looks like:

```
error_log syslog:server=unix:/dev/log;

```

The only error I see is that nginx can’t open /var/log/nginx/error.log.

```
$ nginx -t
nginx: [alert] could not open error log file: open()

```

“/var/log/nginx/error.log” failed (2: Unknown error)  
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
nginx: configuration file /etc/nginx/nginx.conf test failed

Of course /var/log/nginx isn’t there because I’m trying to use syslog.  
If I create /var/log/nginx, nginx starts and I’ll see debugging logs  
there but nothing related to syslog problems.

The permissions on /dev/log look fine:

```
$ ls -l /dev/log
srw-rw-rw- 1 root root 0 Jun 24 12:41 /dev/log=

```

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 24, 2015, 4:01pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/5 "2015-06-24T16:01:23Z")

</div>

On Wed, Jun 24, 2015 at 08:31:31AM -0400, Danomi Czaski wrote:

> > > > nginx/1.8.0 does not seem to be dumping in logs however. The nginx config  
> > > > is
> 
> Of course /var/log/nginx isn’t there because I’m trying to use syslog.  
> If I create /var/log/nginx, nginx starts and I’ll see debugging logs  
> there but nothing related to syslog problems.
> 
> The permissions on /dev/log look fine:
> 
> ```
> $ ls -l /dev/log
> srw-rw-rw- 1 root root 0 Jun 24 12:41 /dev/log=
> 
> ```

did you try increasing log level? If there are no errors, nginx will  
not write anything to log in your case.

you can add one more error\_log directive and point it to some local  
file with write permissions to check there for possible errors.

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 24, 2015, 4:21pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/6 "2015-06-24T16:21:50Z")

</div>

On Wed, Jun 24, 2015 at 10:00 AM, Vladimir H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > > by piping in some stuff to “logger -u /dev/log”  
> > > > > My config looks like:
> 
> did you try increasing log level? If there are no errors, nginx will  
> not write anything to log in your case.
> 
> you can add one more error\_log directive and point it to some local  
> file with write permissions to check there for possible errors.

Okay, I see messages going to syslog, I had to increase the log level  
as you said. Thanks.

It seems like there _must_ be a file logger or nginx won’t start. If I  
don’t want any log file it looks like I have to do something like:

```
error_log /dev/null emerg;
error_log syslog:server=unix:/dev/log debug;

```

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 25, 2015, 1:05am UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/7 "2015-06-25T01:05:56Z")

</div>

> > > > > > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> > > > > > send data to socket for some reasons (check socket permissions, selinux  
> > > > > > “/var/log/nginx/error.log” failed (2: Unknown error)  
> > > > > > srw-rw-rw- 1 root root 0 Jun 24 12:41 /dev/log=  
> > > > > > It seems like there _must_ be a file logger or nginx won’t start. If I  
> > > > > > don’t want any log file it looks like I have to do something like:
> > 
> > error\_log /dev/null emerg;  
> > error\_log syslog:server=unix:/dev/log debug;
> 
> This is intentionally: syslog is not reliable and nginx by default will  
> write logs to files. And there is a simple workaround - you

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![Andrew\_Holway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Andrew\_Holway](https://www.ruby-forum.com/u/Andrew_Holway)\
**Post date:** [June 24, 2015, 4:45pm UTC](https://www.ruby-forum.com/t/nginx-not-logging-to-socket/242393/8 "2015-06-24T16:45:47Z")

</div>

On Wed, Jun 24, 2015 at 10:21:06AM -0400, Danomi Czaski wrote:

> > > > > > Using rsyslog I have set up a logging socket and confirmed that its  
> > > > > > working
> > > 
> > > ```
> > > nginx: configuration file /etc/nginx/nginx.conf test failed
> > > 
> > > ```
> 
> don’t want any log file it looks like I have to do something like:
> 
> ```
> error_log /dev/null emerg;
> error_log syslog:server=unix:/dev/log debug;
> 
> ```

This is intentionally: syslog is not reliable and nginx by default will  
write logs to files. And there is a simple workaround - you just found  
it  
iself.
