0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GCEに「NGINX Unit」を入れる ver.2024

Posted at

前回の記事は、こちら
https://yamayoshi.blogspot.com/2020/04/gcenginx-unitweb.html
セキュリティが強化されたようで、config.json に user を追加しています。
一旦動いてしまえば、Unit 最高。

Flask

$ cd
$ mkdir project1 && cd project1
$ python3 -m venv venv
$ source venv/bin/activate
V pip install Flask
V nano main.py
main.py
from flask import Flask
application = Flask(__name__)
@application.route("/")
def index():
    return "Hello Project1!"
if __name__ == "__main__":
    application.run()
V deactivate

Unit - Ubunt22.04

$ cd
$ sudo -i
# curl --output /usr/share/keyrings/nginx-keyring.gpg https://unit.nginx.org/keys/nginx-keyring.gpg
# nano /etc/apt/sources.list.d/unit.list
/etc/apt/sources.list.d/unit.list
deb [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/ubuntu/ jammy unit
deb-src [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/ubuntu/ jammy unit
# apt update
# apt install unit unit-dev unit-python3.10
# systemctl restart unit

Unit 設定

# nano config.json
config.json
{
    "listeners": {
        "*:80": {
            "pass": "applications/flask_app"
        }
    },
    "applications": {
        "flask_app": {
            "type": "python",
            "user": "<user>",
            "path": "/home/<user>/project1",
            "home": "/home/<user>/project1/venv",
            "module": "main"
        }
    }
}
# curl -X PUT --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/config
# service unit restart

以上です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?