I'm trying to have nginx connect to a uwsgi socket on FreeBSD. I've set the socket to 666 but whenever I issue a request in my browser I can see the following in my nginx logs:

2017/12/12 11:34:04 [crit] 1051#100213: *5 connect() to unix:/home/dashboard/dashboard/dashboard.sock failed (13: Permission denied) while connecting to upstream, client: <IP address>, server: <IP address>, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/dashboard/dashboard/dashboard.sock:", host: "<IP address>"

My nginx processes:

root       1050   0.0  1.5  25496  7280  -  Is   11:11    0:00.00 nginx: master process /usr/local/sbin/nginx
www        1051   0.0  1.6  25496  7756  -  I    11:11    0:00.01 nginx: worker process (nginx)

I believe this is due to my uwsgi processes (emperor, master and workers) run as root while while nginx runs as www.

I've tried setting uwsgi's gid and uid to www but the uwsgi worker will fail with the following error:

*** Starting uWSGI 2.0.15 (64bit) on [Tue Dec 12 11:43:44 2017] ***
compiled with version: 4.2.1 Compatible FreeBSD Clang 4.0.0 (tags/RELEASE_400/final 297347) on 08 December 2017 10:41:56
os: FreeBSD-11.1-RELEASE-p4 FreeBSD 11.1-RELEASE-p4 #0: Tue Nov 14 06:12:40 UTC 2017     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC
nodename: newyork
machine: amd64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /usr/home/ruipacheco
detected binary path: /usr/local/bin/uwsgi-2.7
chdir() to /home/dashboard/dashboard
chdir(): Permission denied [core/uwsgi.c line 2591]
chdir(): Permission denied [core/uwsgi.c line 1613]
Tue Dec 12 11:43:44 2017 - [emperor] curse the uwsgi instance /home/ruipacheco/uwsgi.ini (pid: 967)
Tue Dec 12 11:43:44 2017 - [emperor] removed uwsgi instance /home/ruipacheco/uwsgi.ini

On the other hand if I leave it running as root nginx won't be able to connect to a socket owned by root.

What is the correct procedure to have nginx talk to a uwsgi socket on FreeBSD?

  • You need to check the ownership and permissions on the complete path to your socket. – Michael Hampton Dec 12 '17 at 17:00
  • What are the owner and permissions of each directory in the /home/dashboard/dashboard chain? – Richard Smith Dec 12 '17 at 17:01
  • @RichardSmith The folders are owned by www:www – ruipacheco Dec 12 '17 at 17:50

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.