6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Apache2+WSGI+Flaskを動かす

Last updated at Posted at 2020-09-20

#環境

  • さくらVPS(Ubuntu 18.04.2)
  • Python 3.6.9
  • Apache2

#設定
設定ファイル

/var/www/html/flask
- Hello.py
- test.wsgi
/etc/apache2/sites-available
- wsgi.conf

まずはスクリプト本体。

Hello.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello'

if __name__ == '__main__':
    app.run()

そしてWSGIファイルを作る。

test.wsgi
import sys, site

sys.path.insert(0, '/var/www/html/flask')
from Hello import app as application

Apache側の設定。

# wsgi.conf
<VirtualHost *:80>
serverName (契約したサーバのIPアドレス or ドメイン名)

WSGIDaemonProcess test user=(Pythonを実行するユーザ名)  group=(そのユーザのグループ) threads=5
WSGIScriptAlias / /var/www/html/flask/test.wsgi

<Directory /var/www/html/flask>

WSGIProcessGroup test 
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On

Require all granted

</Directory>
</VirtualHost>

#サーバの再起動
wsgi.confを有効にする。

$ sudo a2ensite wsgi

そしてApacheの再起動。

$ sudo service apache2 restart

これでサイトにアクセスすれば"Hello"が表示されるはず。

#参考にしたもの

6
8
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
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?