nginx(エンジンエックス)とは
- Webサーバの一つ
nginx インストール
- ubuntuから下記コマンド実行
sudo apt update
sudo apt install nginx
- 確認
nginx -v
nginx 起動
- ubuntuから下記コマンド実行
sudo nginx
- ブラウザから
http://localhost
にアクセス
nginxの環境について
- デフォルトのrootフォルダは/var/www/html
- /var/www/html に移動
cd /var/www/html
- ファイルを表示してみる
user01@DESKTOP-5FA6FSN:/var/www/html$ ls
index.nginx-debian.html
-
http://localhost で表示されていた「Welcome ~」は、
index.nginx-debian.html が表示されていた
hello world
- /var/www/html/hello.html を作成
sudo vi hello.html
- hello.htmlに以下のように記述し保存
hello world
- 下記にアクセス
http://localhost/hello.html - 「hello world」と表示されることを確認する
nginxの設定ファイルを見てみよう
cd /etc/nginx
view nginx.conf
※linuxの設定ファイルはだいたい/etc
にある
なぜ/var/www/htmlにあるファイルを参照するのか
- viewコマンドで参照すると下記のような設定がある
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
includeで、さらに他のファイルを読み込んでいる
- includeされている
/etc/nginx/sites-enabled/default
を参照してみる
view sites-enabled/default
- defaultに
root /var/www/html;
の定義があり、ここで設定されたディレクトリにあるファイルを参照できる