LoginSignup
1
0

Nginx と uWSGI で CGI

Last updated at Posted at 2019-05-08

Nginx と uWSGI で CGI を行う方法です。

  1. Nginx の 設定に追加
  2. /etc/nginx/nginx.conf
    (省略)
            location /uwsgi {
                            include uwsgi_params;
                            uwsgi_pass 127.0.0.1:3031;
                    }
    (省略)
    
  3. サーバープログラム
  4. /var/www/html/uwsgi/index.py
    # ---------------------------------------------------------------
    def application(env, start_response):
    	start_response('200 OK', [('Content-Type','text/html; charset=UTF-8')])
    	str_out = "<h1>Hello World</h1>"
    	str_out += "こんにちは<p />"
    	str_out += "<blockquote>"
    	str_out += "May/08/2019<p />"
    	str_out += "</blockquote>"
    #
    	return [bytes(str_out,'utf-8')]
    #
    # ---------------------------------------------------------------
    
  5. uWSGI の起動 (手動)
  6. uwsgi.ini
    [uwsgi]
    master = True
    socket = 127.0.0.1:3031
    wsgi-file = index.py
    stats = 127.0.0.1:9191
    logto = uwsgi.log
    pidfile = uwsgi.pid
    

    起動コマンド

    uwsgi --plugin http,python3 --ini uwsgi.ini
    
  7. ブラウザーで http://hostname/uwsgi にアクセス
  8. image.png

確認したバージョン

$ python --version
Python 3.11.2

$ uwsgi --version
2.0.21-debian

参考情報

uWSGI Basic test

Take into account that Python 3 requires bytes().
1
0
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
1
0