brand new note

ジャズ屋が技術の話をするところ

ubuntuにnginxをインストール

nginxでWebサーバを構築してみよう | YAZ技術ブログ

基本だけどやったメモをのこしておく。

sudo apt install nginx net-tools

net-toolsはnetstatが使えなかったので入れただけ。他人のやってみたを真似してると「その後半のやつ入れる必要ある?」みたいな気持ちによくなるので書いとく。

設定ファイルは/etc/nginx/nginx.confconf.ddefault.confを作成。

なんで設定ファイルが分かれるんだろうと思ってたけど、デーモンで動かすときとフォアグラウンドで動かすときとでは設定ファイルを変えるのがスタンダードらしい。となるとconf.ddはデーモンなのかな。

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ /\.ht {
        deny  all;
    }
}

/usr/share/nginx/htmlも確認。

ekp@ekp-ThinkPad-X1-Carbon-3rd /u/share> cd nginx/
ekp@ekp-ThinkPad-X1-Carbon-3rd /u/s/nginx> ls
html/  modules@  modules-available/
ekp@ekp-ThinkPad-X1-Carbon-3rd /u/s/nginx> cd html/
ekp@ekp-ThinkPad-X1-Carbon-3rd /u/s/n/html> ls
index.html
ekp@ekp-ThinkPad-X1-Carbon-3rd /u/s/n/html> cat index.html 
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

特にファイアウォールもないのでブラウザからこのページが見えるか確認。

f:id:frazz:20210527233715p:plain

コンテナ上でnginxを立ち上げたことはあったけど、あれはコンテナの勉強だったので改めて分離してやってみた。確かにwelcomeページは見たことがあるので外側の箱は関係ないんだね(当たり前)。0歩目なのでいずれ必ず深堀りしないといけない。気が向くまでは一旦他のことをする。