====== uWSGI - WSGI アプリケーションコンテナ ====== {{:python:uwsgi_logo.svg?200|uWSGI Logo}}\\ \\ **uWSGI** は、「ホスティングサービスを構築するためのフルスタックの開発を的とする」ソフトウェアアプリケーションです。プロジェクトでサポートされている最初のプラグインである [[https://ja.wikipedia.org/wiki/Web_Server_Gateway_Interface|Web Server Gateway Interface(WSGI; ウィズギー)]] にちなんで命名されている。\\ \\ uWSGIは、Cherokee や Nginx などの Web サーバーと組み合わせて Python Web アプリケーションを提供するためによく使用され、uWSGI のネイティブ uwsgi プロトコルを直接サポートする。\\ [[wp>UWSGI|uWSGI - Wikipedia]] より\\ \\ 本家: [[https://uwsgi-docs.readthedocs.io/en/latest/|The uWSGI project — uWSGI 2.0 documentation]]\\ ソースコード: [[https://github.com/unbit/uwsgi|GitHub - unbit/uwsgi: uWSGI application server container]]\\ ===== dnf によるインストール ===== $ sudo dnf install uwsgi uwsgi-plugin-python3 メタデータの期限切れの最終確認: 0:00:44 時間前の 2020年04月12日 16時55分24秒 に実施しまし た。 依存関係が解決しました。 ========================================================================================== Package Architecture Version Repository Size ========================================================================================== インストール: uwsgi x86_64 2.0.18-2.fc31 fedora 383 k uwsgi-plugin-python3 x86_64 2.0.18-2.fc31 fedora 78 k 依存関係のインストール: uwsgi-plugin-common x86_64 2.0.18-2.fc31 fedora 46 k トランザクションの概要 ========================================================================================== インストール 3 パッケージ 合計サイズ: 507 k インストール済みのサイズ: 1.2 M これでよろしいですか? [y/N]: y パッケージのダウンロード: [SKIPPED] uwsgi-2.0.18-2.fc31.x86_64.rpm: Already downloaded [SKIPPED] uwsgi-plugin-common-2.0.18-2.fc31.x86_64.rpm: Already downloaded [SKIPPED] uwsgi-plugin-python3-2.0.18-2.fc31.x86_64.rpm: Already downloaded ------------------------------------------------------------------------------------------ 合計 50 MB/s | 507 kB 00:00 トランザクションの確認を実行中 トランザクションの確認に成功しました。 トランザクションのテストを実行中 トランザクションのテストに成功しました。 トランザクションを実行中 準備 : 1/1 scriptletの実行中: uwsgi-2.0.18-2.fc31.x86_64 1/3 インストール中 : uwsgi-2.0.18-2.fc31.x86_64 1/3 scriptletの実行中: uwsgi-2.0.18-2.fc31.x86_64 1/3 Executing systemd post-install tasks インストール中 : uwsgi-plugin-common-2.0.18-2.fc31.x86_64 2/3 インストール中 : uwsgi-plugin-python3-2.0.18-2.fc31.x86_64 3/3 scriptletの実行中: uwsgi-plugin-python3-2.0.18-2.fc31.x86_64 3/3 検証 : uwsgi-2.0.18-2.fc31.x86_64 1/3 検証 : uwsgi-plugin-common-2.0.18-2.fc31.x86_64 2/3 検証 : uwsgi-plugin-python3-2.0.18-2.fc31.x86_64 3/3 インストール済み: uwsgi-2.0.18-2.fc31.x86_64 uwsgi-plugin-common-2.0.18-2.fc31.x86_64 uwsgi-plugin-python3-2.0.18-2.fc31.x86_64 完了しました! ==== uWSGI Emperor Service の有効化 ==== $ sudo systemctl enable uwsgi Created symlink /etc/systemd/system/multi-user.target.wants/uwsgi.service → /usr/lib/systemd/system/uwsgi.service. ==== uwsgi 動作確認 ==== Python バージョン確認\\ $ python -VV Python 3.7.6 (default, Jan 30 2020, 09:44:41) [GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] Python 仮想環境の作成\\ $ python -m venv py3dj3_venv Python 仮想環境の有効化\\ $ . py3dj3_venv/bin/activate (py3dj3_venv) $ Python 仮想環境の pip を更新\\ (py3dj3_venv) $ python -m pip install --upgrade pip Collecting pip Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl Installing collected packages: pip Found existing installation: pip 19.1.1 Uninstalling pip-19.1.1: Successfully uninstalled pip-19.1.1 Successfully installed pip-20.0.2 Django のインストール\\ (py3dj3_venv) $ pip install django Collecting django Using cached Django-3.0.5-py3-none-any.whl (7.5 MB) Collecting sqlparse>=0.2.2 Using cached sqlparse-0.3.1-py2.py3-none-any.whl (40 kB) Collecting pytz Using cached pytz-2019.3-py2.py3-none-any.whl (509 kB) Collecting asgiref~=3.2 Using cached asgiref-3.2.7-py2.py3-none-any.whl (19 kB) Installing collected packages: sqlparse, pytz, asgiref, django Successfully installed asgiref-3.2.7 django-3.0.5 pytz-2019.3 sqlparse-0.3.1 Django プロジェクトの作成\\ (py3dj3_venv) $ django-admin startproject django_project Python 仮想環境の終了\\ (py3dj3_venv) $ deactivate $ 一番シンプルな uwsgi コマンドで Django アプリの動作確認を行う\\ $ uwsgi --http-socket :8000 --plugin python3 --virtualenv /home/tomoyan/py3dj3_venv --chdir /home/tomoyan/django_project --wsgi-file django_project/wsgi.py *** Starting uWSGI 2.0.18 (64bit) on [Tue Apr 14 03:23:45 2020] *** compiled with version: 9.1.1 20190605 (Red Hat 9.1.1-2) on 27 July 2019 00:00:00 os: Linux-4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 nodename: Cmon machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 4 current working directory: /home/tomoyan detected binary path: /usr/sbin/uwsgi chdir() to /home/tomoyan/django_project *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 50741 your memory page size is 4096 bytes detected max file descriptor number: 1048576 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to TCP address :8000 fd 3 Python version: 3.7.6 (default, Jan 30 2020, 09:44:41) [GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] PEP 405 virtualenv detected: /home/tomoyan/py3dj3_venv Set PythonHome to /home/tomoyan/py3dj3_venv *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x98b450 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72920 bytes (71 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x98b450 pid: 5711 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 5711, cores: 1) [[http://localhost:8000|]] にブラウザでアクセスする。\\ {{:python:uwsgi_django_operation_check_001.png?600|uWSGI Django Operation Check}}\\ uwsgi コマンドを **Ctrl + C** で終了\\ [pid: 5711|app: 0|req: 1/1] 127.0.0.1 () {42 vars in 890 bytes} [Mon Apr 13 18:24:59 2020] GET / => generated 16351 bytes in 21 msecs (HTTP/1.1 200) 4 headers in 123 bytes (1 switches on core 0) Not Found: /static/admin/css/fonts.css [pid: 5711|app: 0|req: 2/2] 127.0.0.1 () {40 vars in 805 bytes} [Mon Apr 13 18:24:59 2020] GET /static/admin/css/fonts.css => generated 2025 bytes in 21 msecs (HTTP/1.1 404) 4 headers in 129 bytes (1 switches on core 0) [pid: 5711|app: 0|req: 3/3] 127.0.0.1 () {42 vars in 884 bytes} [Mon Apr 13 18:27:42 2020] GET / => generated 16351 bytes in 14 msecs (HTTP/1.1 200) 4 headers in 123 bytes (1 switches on core 0) Not Found: /static/admin/css/fonts.css [pid: 5711|app: 0|req: 4/4] 127.0.0.1 () {40 vars in 805 bytes} [Mon Apr 13 18:27:42 2020] GET /static/admin/css/fonts.css => generated 2025 bytes in 8 msecs (HTTP/1.1 404) 4 headers in 129 bytes (1 switches on core 0) Ctrl + C を入力 $ ===== uWSGI Emperor Service の ini ファイルを設定 ===== Django アプリのミニマム設定\\ http-socket = :8000 plugin = python3 virtualenv = /usr/local/lsws/Example/py3dj3_venv chdir = /usr/local/lsws/Example/django_project wsgi-file = django_project/wsgi.py uWSGI Emperor Service の開始 $ sudo systemctl start uwsgi uWSGI Emperor Service リッスン確認\\ $ sudo netstat -anp4 | grep uwsgi tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 986/uwsgi ===== pip によるインストール ===== $ pip install uwsgi Collecting uwsgi Downloading uwsgi-2.0.18.tar.gz (801 kB) |████████████████████████████████| 801 kB 738 kB/s Installing collected packages: uwsgi Running setup.py install for uwsgi ... done Successfully installed uwsgi-2.0.18 ===== Apache 2.4 への mod_uwsgi.so のインストール ===== $ sudo dnf install httpd-devel $ sudo -s # cd ~ # curl -O https://raw.githubusercontent.com/unbit/uwsgi/master/apache2/mod_uwsgi.c % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 22715 100 22715 0 0 60251 0 --:--:-- --:--:-- --:--:-- 60251 # apxs -i -a -c mod_uwsgi.c /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o mod_uwsgi.lo mod_uwsgi.c && touch mod_uwsgi.slo mod_uwsgi.c: 関数 ‘uwsgi_handler’ 内: mod_uwsgi.c:572:7: 警告: 真偽値として使われる代入のまわりでは、丸括弧の使用をお勧めします [-Wparentheses] 572 | if (hret = ap_scan_script_header_err_brigade(r, bb, NULL)) { | ^~~~ mod_uwsgi.c: 関数 ‘cmd_uwsgi_force_wsgi_scheme’ 内: mod_uwsgi.c:601:21: 警告: ‘&’ の被演算子内にある比較の周りに小括弧を付けることを推奨します [-Wparentheses] 601 | if (strlen(scheme) < 9 & strlen(scheme) > 0) { | ~~~~~~~~~~~~~~~^~~ mod_uwsgi.c: 関数 ‘cmd_uwsgi_max_vars’ 内: mod_uwsgi.c:614:13: 警告: 使用されない変数 ‘val’ です [-Wunused-variable] 614 | int val ; | ^~~ mod_uwsgi.c: 関数 ‘cmd_uwsgi_socket2’ 内: mod_uwsgi.c:705:6: 警告: 真偽値として使われる代入のまわりでは、丸括弧の使用をお勧めします [-Wparentheses] 705 | if (tcp_port = strchr(path, ':')) { | ^~~~~~~~ mod_uwsgi.c: 関数 ‘cmd_uwsgi_socket’ 内: mod_uwsgi.c:738:6: 警告: 真偽値として使われる代入のまわりでは、丸括弧の使用をお勧めします [-Wparentheses] 738 | if (tcp_port = strchr(path, ':')) { | ^~~~~~~~ /usr/lib64/apr-1/build/libtool --silent --mode=link gcc -Wl,-z,relro,-z,now -o mod_uwsgi.la -rpath /usr/lib64/httpd/modules -module -avoid-version mod_uwsgi.lo /usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' mod_uwsgi.la /usr/lib64/httpd/modules /usr/lib64/apr-1/build/libtool --mode=install install mod_uwsgi.la /usr/lib64/httpd/modules/ libtool: install: install .libs/mod_uwsgi.so /usr/lib64/httpd/modules/mod_uwsgi.so libtool: install: install .libs/mod_uwsgi.lai /usr/lib64/httpd/modules/mod_uwsgi.la libtool: install: install .libs/mod_uwsgi.a /usr/lib64/httpd/modules/mod_uwsgi.a libtool: install: chmod 644 /usr/lib64/httpd/modules/mod_uwsgi.a libtool: install: ranlib /usr/lib64/httpd/modules/mod_uwsgi.a libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/lib64/httpd/modules ---------------------------------------------------------------------- Libraries have been installed in: /usr/lib64/httpd/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /usr/lib64/httpd/modules/mod_uwsgi.so # chmod 755 /usr/lib64/httpd/modules/mod_uwsgi.so # vi /etc/httpd/conf/httpd.conf # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so # LoadModule uwsgi_module modules/mod_uwsgi.so Include conf.modules.d/*.conf ===== uWSGI 関連パッケージ ===== $ dnf search uwsgi メタデータの期限切れの最終確認: 0:12:32 時間前の 2020年06月27日 04時15分49秒 に実施しました。 ================================= Name 完全一致: uwsgi ================================== uwsgi.x86_64 : Fast, self-healing, application container server ============================== Name & Summary 一致: uwsgi =============================== uwsgi-docs.x86_64 : uWSGI - Documentation uwsgi-alarm-curl.x86_64 : uWSGI - Curl alarm plugin uwsgi-alarm-xmpp.x86_64 : uWSGI - Curl alarm plugin uwsgi-plugin-rack.x86_64 : uWSGI - Ruby rack plugin uwsgi-plugin-sqlite3.x86_64 : uWSGI - SQLite3 plugin uwsgi-logger-file.x86_64 : uWSGI - logfile logger plugin uwsgi-logger-pipe.x86_64 : uWSGI - logpipe logger plugin uwsgi-plugin-lua.x86_64 : uWSGI - Plugin for LUA support uwsgi-plugin-pam.x86_64 : uWSGI - Plugin for PAM support uwsgi-plugin-php.x86_64 : uWSGI - Plugin for PHP support uwsgi-plugin-pty.x86_64 : uWSGI - Plugin for PTY support uwsgi-plugin-rpc.x86_64 : uWSGI - Plugin for RPC support uwsgi-logger-syslog.x86_64 : uWSGI - syslog logger plugin uwsgi-logger-zeromq.x86_64 : uWSGI - ZeroMQ logger plugin uwsgi-logger-redis.x86_64 : uWSGI - redislog logger plugin uwsgi-plugin-ldap.x86_64 : uWSGI - Plugin for LDAP support uwsgi-plugin-psgi.x86_64 : uWSGI - Plugin for PSGI support uwsgi-plugin-ruby.x86_64 : uWSGI - Plugin for Ruby support uwsgi-logger-rsyslog.x86_64 : uWSGI - rsyslog logger plugin uwsgi-logger-crypto.x86_64 : uWSGI - logcrypto logger plugin uwsgi-logger-socket.x86_64 : uWSGI - logsocket logger plugin uwsgi-plugin-cache.x86_64 : uWSGI - Plugin for cache support uwsgi-plugin-dummy.x86_64 : uWSGI - Plugin for Dummy support uwsgi-plugin-geoip.x86_64 : uWSGI - Plugin for GeoIP support uwsgi-logger-graylog2.x86_64 : uWSGI - Graylog2 logger plugin uwsgi-plugin-common.x86_64 : uWSGI - Common plugins for uWSGI uwsgi-plugin-gccgo.x86_64 : uWSGI - Plugin for GoLang support uwsgi-plugin-ssi.x86_64 : uWSGI - Server Side Includes plugin uwsgi-plugin-cplusplus.x86_64 : uWSGI - Plugin for C++ support uwsgi-plugin-nagios.x86_64 : uWSGI - Plugin for Nagios support uwsgi-plugin-ugreen.x86_64 : uWSGI - Plugin for uGreen support uwsgi-plugin-webdav.x86_64 : uWSGI - Plugin for WebDAV support uwsgi-router-raw.x86_64 : uWSGI - Plugin for Raw Router support uwsgi-router-ssl.x86_64 : uWSGI - Plugin for SSL router support uwsgi-plugin-rrdtool.x86_64 : uWSGI - Plugin for RRDTool support uwsgi-router-fast.x86_64 : uWSGI - Plugin for FastRouter support uwsgi-plugin-coroae.x86_64 : uWSGI - Plugin for PERL Coro support uwsgi-plugin-fiber.x86_64 : uWSGI - Plugin for Ruby Fiber support uwsgi-plugin-mono.x86_64 : uWSGI - Plugin for Mono / .NET support uwsgi-router-hash.x86_64 : uWSGI - Plugin for Hash router support uwsgi-router-http.x86_64 : uWSGI - Plugin for HTTP router support uwsgi-plugin-airbrake.x86_64 : uWSGI - Plugin for AirBrake support uwsgi-plugin-mongrel2.x86_64 : uWSGI - Plugin for Mongrel2 support uwsgi-plugin-notfound.x86_64 : uWSGI - Plugin for notfound support uwsgi-plugin-zergpool.x86_64 : uWSGI - Plugin for zergpool support uwsgi-devel.i686 : uWSGI - Development header files and libraries uwsgi-devel.x86_64 : uWSGI - Development header files and libraries uwsgi-logger-systemd.x86_64 : uWSGI - systemd journal logger plugin uwsgi-plugin-dumbloop.x86_64 : uWSGI - Plugin for Dumb Loop support uwsgi-plugin-python3.x86_64 : uWSGI - Plugin for Python 3.7 support uwsgi-router-cache.x86_64 : uWSGI - Plugin for Cache router support uwsgi-router-redis.x86_64 : uWSGI - Plugin for Redis router support uwsgi-router-uwsgi.x86_64 : uWSGI - Plugin for uWSGI router support uwsgi-plugin-curl-cron.x86_64 : uWSGI - Plugin for CURL Cron support uwsgi-plugin-glusterfs.x86_64 : uWSGI - Plugin for GlusterFS support uwsgi-stats-pusher-file.x86_64 : uWSGI - File Stats Pusher for uWSGI uwsgi-log-encoder-msgpack.x86_64 : uWSGI - msgpack log encoder plugin uwsgi-router-radius.x86_64 : uWSGI - Plugin for Radius router support uwsgi-router-spnego.x86_64 : uWSGI - Plugin for SPNEgo router support uwsgi-router-static.i686 : uWSGI - Plugin for Static router support uwsgi-router-static.x86_64 : uWSGI - Plugin for Static router support uwsgi-router-xmldir.x86_64 : uWSGI - Plugin for XMLDir router rupport uwsgi-transformation-gzip.x86_64 : uWSGI - GZip Transformation plugin uwsgi-router-tuntap.x86_64 : uWSGI - Plugin for TUN/TAP router support uwsgi-plugin-carbon.x86_64 : uWSGI - Plugin for Carbon/Graphite support uwsgi-plugin-xattr.x86_64 : uWSGI - Plugin for Extra Attributes support uwsgi-router-expires.x86_64 : uWSGI - Plugin for Expires router support uwsgi-router-forkpty.x86_64 : uWSGI - Plugin for ForkPTY router support uwsgi-router-metrics.x86_64 : uWSGI - Plugin for Metrics router support uwsgi-router-rewrite.x86_64 : uWSGI - Plugin for Rewrite router support uwsgi-plugin-spooler.x86_64 : uWSGI - Plugin for Remote Spooling support uwsgi-stats-pusher-socket.x86_64 : uWSGI - Socket Stats Pusher for uWSGI uwsgi-stats-pusher-statsd.x86_64 : uWSGI - StatsD Stats Pusher for uWSGI uwsgi-stats-pusher-zabbix.x86_64 : uWSGI - Zabbix Stats Pusher for uWSGI uwsgi-plugin-xslt.x86_64 : uWSGI - Plugin for XSLT transformation support uwsgi-router-redirect.x86_64 : uWSGI - Plugin for Redirect router support uwsgi-transformation-tofile.x86_64 : uWSGI - ToFile Transformation plugin uwsgi-plugin-rbthreads.x86_64 : uWSGI - Ruby native threads support plugin uwsgi-router-memcached.x86_64 : uWSGI - Plugin for Memcached router support uwsgi-transformation-chunked.x86_64 : uWSGI - Chunked Transformation plugin uwsgi-transformation-toupper.x86_64 : uWSGI - ToUpper Transformation plugin uwsgi-router-basicauth.x86_64 : uWSGI - Plugin for Basic Auth router support uwsgi-transformation-offload.x86_64 : uWSGI - Off-Load Transformation plugin uwsgi-transformation-template.x86_64 : uWSGI - Template Transformation plugin uwsgi-plugin-cheaper-busyness.x86_64 : uWSGI - Plugin for Cheaper Busyness algos uwsgi-plugin-python3-gevent.x86_64 : uWSGI - Plugin for Python 3.7 GEvent support uwsgi-plugin-python3-greenlet.x86_64 : uWSGI - Plugin for Python 3.7 Greenlet support uwsgi-plugin-python3-tornado.x86_64 : uWSGI - Plugin for Tornado (Python 3.7) support python3-uwsgidecorators.x86_64 : Python 3.7 decorators providing access to the uwsgi API ===== 参考文献 ===== [[https://uwsgi-docs.readthedocs.io/en/latest/|The uWSGI project — uWSGI 2.0 documentation]]\\ [[https://uwsgi-docs.readthedocs.io/en/latest/Apache.html|Apache support — uWSGI 2.0 documentation]]\\ [[https://chriswarrick.com/blog/2016/02/10/deploying-python-web-apps-with-nginx-and-uwsgi-emperor/|Deploying Python Web Applications with nginx and uWSGI Emperor | Chris Warrick]]\\ [[https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/uwsgi/|How to use Django with uWSGI | Django documentation | Django]]\\ [[https://qiita.com/11ohina017/items/da2ae5b039257752e558|uWSGIのiniファイルの文法まとめ - Qiita]]\\