LoginSignup
2
3

だれも解説しないけど、NginxをWindowsで起動し、Flask APPを動作させてみた

Posted at

目的

Nginx Windows版があるのにも関わらず、なぜかWSL2やUbuntuなどの記事が目立つ、筆者はインドの方のビデオを見てひらめき、そして試してみたらできた。

必要なもの

  1. Flask APP
  2. Nginx For Windows
  3. Waitress(pip install済)

やり方

  1. Nginx for Windowsをダウンロードして、解凍しておく
  2. pip install waitressでwaitressをインストール
  3. waitressのポートを5000に振っておく
  4. nginx.confを開き、以下のようにしておく

#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
       listen       3000;

       location / {
            proxy_pass http://localhost:5000;
  
       }
    }
}

5.Flaskは以下のようにしておく

from waitress import serve

# APP本体は省略

if __name__ == "__main__":
    serve(app, host='0.0.0.0', port=5000)

6.python app.pyを実行

7.Nginxを起動

8.ブラウザからlocalhost:3000でFlaskアプリが見えたら成功

以上、検討を祈る

2
3
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
2
3