Ubuntu19.10 pythonでwebサーバーを起動する

Ubuntu19.10 pythonでwebサーバーを起動する

pythonを利用すると簡単にwebサーバーを起動することが可能

環境

  • OS  Ubuntu19.10
  • python 3.7.5

python確認

既にインストールされているpythonを利用する

## バージョン確認
python3 --version

<出力結果>
Python 3.7.5rc1

ルートディレクトリを作成

ルートディレクトリを作成します

## ディレクトリ作成
mkdir python-web

html作成

表示用のhtmlを作成します。下記の内容でindex.htmlを作成し保存します

<html>
<head>
<title>
Title
</title>
</head>
<body>
<h1>
Hello World!!
</h1>
</body>
</html>

サーバー起動

pythonの標準WEBライブラリを利用して、WEBサーバーを起動します

## サーバー起動
python3 -m http.server 8080

ブラウザよりhttp://localhost:8080にアクセスすると下記の画面が表示されます