LoginSignup
6
4

More than 5 years have passed since last update.

NGINX、uWSGI間をソケット通信する場合、/tmpに.sockを置いちゃダメ!(Centos 7)

Last updated at Posted at 2019-04-04

結論から

CentOS 7ではプログラムごとに/tmpが別に用意されるらしく、nginxから見える/tmpとuwsgiから見える/tmpが違うため、/tmp/uwsgi.sockがnginxから見つからない、という事態に陥っていた。
/runを使う
→ そのままだと再起動時に/run/appが削除されるため、永続化する

それぞれの設定

nginx.conf
server {
  ...
  location / {
    include uwsgi_params;
    uwsgi_ignore_client_abort on;
    uwsgi_pass unix:///tmp/uwsgi/app.sock -> unix:///run/app/app.sock;
  }
}
uwsgi.ini
[uwsgi]

# ...

#socket file's location
socket = /tmp/uwsgi/app.sock -> /run/app/app.sock

uid = app
gid = app
#pid
pidfile = /tmp/uwsgi/app.pid -> /tmp/app/app.pid

#permissions for the socket file
chmod-socket = 666

logto = /var/log/uwsgi/app.log

# ...

/run/uwsgiではなく/run/appにしているのはuwsgiとは別のユーザーを使いたいから。

sudo mkdir -p /run/app
sudo chown app:app /run/app
/etc/tmpfiles.d/app.conf
#Type   Path                    Mode    UID     GID     Age     Argument
d       /var/run/app            0755    app     app     -

参考

python - Got 'No such file or directory' error while configuring nginx and uwsgi - Stack Overflow
nginx unix domain socket error - Server Fault

CentOS 7 : /var/run 直下に作ったディレクトリが消えないようにする - eTuts+ Server Tutorial

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4