• Skip to main content
  • Skip to primary sidebar

学習記録

flask

さくらvpsにflaskを入れてwebapp作成

2018年8月10日 by 河副 太智 Leave a Comment

rootログイン

FTPでのファイル転送はrootで行う為に以下のサイトを参考

Ubuntu 16.04: rootでログインする

ソフトウェアのインストール

– Go to the server root directory with “cd /”
– yumでInstall required software with
“yum install python-virtualenv nginx gunicorn supervisor python-pip”

– apt-getでInstall required software with “
apt-get install python-virtualenv nginx gunicorn supervisor python-pip

 

ディレクトリの作成

– Create a new directory for the virtual environment with
“mkdir /opt/envs”

– Create a virtual environment with virtualenv
“virtualenv /opt/envs/virtual”

– Activate the virtual environment
“. /opt/envs/virtual/bin/activate”

– Install Python dependencies
“pip install bokeh”
“pip install flask”
“pip install gunicorn”

– Create a new directory inside the nginx server
“mkdir /var/log/nginx/flask”

– Create a new directory for uploading app files
“mkdir /opt/webapps” “mkdir /opt/webapps/bokehflask”

 

configuration filesの作成

– Make sure you have your configuration files ready
which are bokeh_serve.conf, flask.conf and default.

 

FTPアップロード

– Locate your local project directory on the left panel and select your
Python files and the templates directory or any other associated local directory,
but not configuration files

– Locate and select the server directory on the right panel and click Upload
/opt/webapps/bokehflaskにapp.pyとrandom_generator.pyをアップする

 

– Upload the file named “default” to
/etc/nginx/sites-available
using the same procedure

– Upload files
“bokeh_serve.conf”
and
“flask.conf”
to /etc/supervisor/conf.d using the same procedure

サーバー上での調整

–  app.py を編集

以下のコマンドで開く
“nano /opt/webapps/bokehflask/app.py”

– インポート文を追加
“from werkzeug.contrib.fixers import ProxyFix”
to the remote app.py file.

– Modify the index function as follows:

1
2
3
4
5
def index():
    url="http://104.236.40.212:5006"
    session=pull_session(url=url,app_path="/random_generator")
    bokeh_script=autoload_server(None,app_path="/random_generator",session_id=session.id, url=url)
    return render_template("index.html", bokeh_script=bokeh_script)

– Add “app.wsgi_app = ProxyFix(app.wsgi_app)” to the remote app.py file after the index function.
– Save the file by pressing Control-X, then type y and then hit Enter.

–  bokeh_serve.confを編集

以下のコマンドで開く
“nano /etc/supervisor/conf.d/bokeh_serve.conf”
and put your IP for –allow-websocket-origin and your IP and port 5006 for –host

 

実行

– Start the nginx webserver with
“service nginx restart”

– Start supervisor with
“service supervisor restart”

– Start flask with
“supervisorctl restart flask”

– Start bokeh server with
“supervisorctl restart bokeh_serve”

– Visit your app in the browswer at http://160.16.225.109 (put your own IP)

Filed Under: Bokeh, flask

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in