18

I use fedora 17, and when I setup nginx with uwsgi using unix domain socket, when I place the socket in a directory with proper permission it's ok, but when I place the socket in the /tmp it will cause nginx error:

connect() to unix:/tmp/MySite.sock failed (2: No such file or directory) while connecting to upstream

The file does exist and has read/write permission for nginx user. But what cause this error, its really drive me crazy, can somebody figure it out.

3 Answers 3

42

You can't place sockets intended for interprocess communication in /tmp.

For security reasons, recent versions of Fedora use namespaced temporary directories, meaning every service sees a completely different /tmp and can only see its own files in that directory.

To resolve the issue, place the socket in a different directory, such as /run (formerly known as /var/run).

3
  • 1
    /run is not writable for a regular user though
    – hostmaster
    Commented Dec 12, 2014 at 9:26
  • 1
    /run is not writable directly, but you can instruct systemd to create a directory under it which is writable by both processes. Commented Mar 4, 2015 at 13:04
  • To help those searching, this also applies to centos 7, and moving the socket-folder to /run worked. It's not easy to find this issue, because every account can see the folder and file in tmp (set 777 to test), so you'd never guess that processes could not.
    – JosephK
    Commented Mar 30, 2019 at 11:23
0

YES! THIS HELPED!

Was seeing check-startup-logs messages from uwsgi, but had no data in the startup logs, wasn't able to find out what was happening. Turned out, I needed to change the sock file to a non-/tmp location, and add:

catch-exceptions = true

to the wsgi's ini file. turned out, I'd specified logging filehandler location to a non-existent directory, so it couldn't log the errors in the first place.

0

Basically, the problem arises with ONE process setting up the sock in the /tmp path, but it would not be visible by ANOTHER process.

There is a setting in the service config, which would block files created by different process, even though using the same user.

Find your service config file (ex: /etc/systemd/system/myapp.service) and then on add this setting: PrivateTmp=No to both your services.

[Service]
...
PrivateTmp=No

more info about systemd units here:

https://www.freedesktop.org/software/systemd/man/systemd.unit.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .