LoginSignup
7
6

More than 1 year has passed since last update.

簡単な uwsgi の使い方

Last updated at Posted at 2018-01-13

簡単な uwsgi の使い方です。

参考ページ
Quickstart for Python/WSGI applications

インストール

Arch Linux

sudo pacman -S uwsgi
sudo pacman -S  uwsgi-plugin-python

Ubuntu

sudo apt install uwsgi
sudo apt install uwsgi-plugin-python3

バージョンの確認

$ uwsgi --version
2.0.21

サーバーのプログラム

foobar.py
#
#	foobar.py
#
#						Jan/13/2017
# 
# ------------------------------------------------------------------
def application(env, start_response):
	start_response('200 OK', [('Content-Type','text/html')])
	rvalue = b"Hello World\n"
	rvalue += b"\tTest\n"
	rvalue += b"\tJan/13/2017\n"
	return [rvalue]
# ------------------------------------------------------------------

サーバーの起動

uwsgi --plugin http,python --http :9090 --wsgi-file foobar.py

クライアントで確認

$ curl http://localhost:9090
Hello World
	Test
	Jan/13/2017

確認したバージョン

$ python --version
Python 3.11.3

Ubuntu で使う場合

ini ファイルを使います。

ubuntu.ini
chdir=/home/uchida/projects/qiita/get_qiita/p0169
socket = 127.0.0.1:3031
plugins-dir = /usr/lib/uwsgi/
plugins = /usr/lib/uwsgi/plugins/python311_plugin.so
plugins = /usr/lib/uwsgi/plugins/http_plugin.so
wsgi-file=foobar.py
 
# アクセス許可ホスト:ポート
http=0.0.0.0:9090

サーバーの起動

uwsgi ubuntu.ini

クライアントで接続

$ curl http://0.0.0.0:9090
Hello World
	Test
	Jan/13/2017

ini ファイルを使わないでサーバーを起動する方法

uwsgi --plugin http,python3 --http :9090 --wsgi-file foobar.py
7
6
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
7
6