3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

nginxサーバのrootディレクトリをどこに置くべきか

Last updated at Posted at 2021-03-19

OSごとにindex.htmlの場所が異なる

alpineにnginxを入れて使おうとしたが、今までubuntuしか使っていなかったため、ディレクトリ構造が異なり、rootディレクトリをどこに置くべきかわからなかった。

コマンドでの検索

/ # find / -type f -name "*.html"

/var/lib/nginx/html/index.html
/var/lib/nginx/html/50x.html

confファイルも探すことを兼ねて、以下なら一発で調べられる。

/ # find / -type d -name nginx | xargs grep -r html

/etc/nginx/http.d/default.conf: location = /404.html {
/etc/nginx/mime.types:    text/html                                        html htm shtml;
/etc/nginx/mime.types:    application/xhtml+xml                            xhtml;
grep: /var/lib/nginx/run: No such file or directory
/var/lib/nginx/html/index.html:<!DOCTYPE html>
/var/lib/nginx/html/index.html:<html>
/var/lib/nginx/html/index.html:</html>
/var/lib/nginx/html/50x.html:<!DOCTYPE html>
/var/lib/nginx/html/50x.html:<html>
/var/lib/nginx/html/50x.html:</html>
/usr/share/nginx/http-default_server.conf:      location = /404.html {

正解は存在しない?

自分としては、今のところ、index.htmlを配置する場所の候補としては、2つの選択肢があリます。

  • インストール時にデフォルトでindex.htmlが配置されている場所に合わせる。
  • nginxの公式Dockerイメージで配置されている場所に合わせる

自分は、デフォルトでindex.htmlが配置されている場所に合わせて作っていくことにしました。

ファイルシステム階層標準

追記 2021/04/22

Linuxのファイルシステムでは、ある程度の役割が予めルールとして決められているようです。
答えとしては、/var/wwwに置くのがよいようです。

Linuxを含めたUnix互換OSにはFHS(Filesystem Hierarchy Standard)という、ファイルシステムの標準的なディレクトリー構成を定めたものがあり、/varは「頻繁に内容が変化するようなファイルの置き場所」ということが規定されています。

Webサイトを構成するファイル群(HTMLファイルやスクリプトファイル等)は、当然のことながら頻繁に更新される性質のものなので、その置き場所としては/varディレクトリーの下にWebサイトであることを示すwwwディレクトリーを作り、その中に納めるのが相応しかろうということです。

参考 : nginx - なぜWebデータを/var/wwwに置かないといけないのか?|teratail

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?