
私は答えを見つけようとしましたが、ほとんどの人はこのエラーを得ませんでしuwsgi
たGunicorn
。
nginx
エラーログには、次の出力があります。
2019/09/20 17:23:20 [crit] 28847#28847: *2 connect() to unix:/home/ubuntu/app_test/app_test.sock failed (13: Permission denied) while connecting to upstream, client: <client-ip>, server: <server-ip>, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/app_test/app_test.sock:/", host: "<ip-address>"
nginx
sites-available
以下を指すsimlinkがあるディレクトリに、次のアプリケーション用の設定ファイルがありますsites-enabled
。
server {
listen 80;
server_name <server-ip>;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/app_test/app_test.sock;
}
}
サービスファイルです/etc/systemd/system/app_test.service
[Unit]
Description=Gunicorn instance to serve app_test
After=network.target
[Service]
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/app_test
Environment="PATH=/home/ubuntu/app_test/appenv/bin"
ExecStart=/home/ubuntu/app_test/appenv/bin/gunicorn --workers 3 --bind unix:app_test.sock -m 002 wsgi:app
[Install]
WantedBy=multi-user.target
(しかし、確実にするためにソケットファイルもマスクしてみました007
。サービスを再起動した後でもログの応答はまだ同じですnginx
。)
app_test.py
ファイルは次のとおりです。
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
app.run(host='0.0.0.0')
最後に、次のようになりますwsgi.py
。
from app_test import app
if __name__ == "__main__":
app.run()
答え1
Gunicornサービスファイルでエラーが発生します。グループ単位で実行するnginx
ように構成されているため、www-data
ファイルにアクセスできませんapp_test.sock
。グループ設定を次のように変更しましたが、www-data
これでうまくいきます!