0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

nginxのシンボリックファイルとは

Last updated at Posted at 2024-07-14

シンボリックリンクとは

シンボリックリンク(symbolic link)は、ファイルシステム上の特殊なタイプのファイルで、別のファイルやディレクトリへの参照を提供するもの。(シンボリックリンクは、別のファイルやディレクトリへのポインタやショートカットのようなもの。)

作成コマンド

ln -s ターゲット リンク名

作成例

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/site1.conf
sudo ln -s /etc/nginx/sites-available/site1.conf /etc/nginx/sites-enabled/

メリット

シンボリックリンクを使用する主な利点:

  1. 柔軟性: サイトの有効/無効を簡単に切り替えられる
  2. 安全性: 元のファイルを変更せずに設定を管理できる
  3. 整理: 全ての設定と有効な設定を分けて管理できる
  4. スケーラビリティ: 多数のサイトを効率的に管理可能

シンボリックリンクを使用しない場合

  1. 設定ファイルをコピーする必要がある
  2. ファイルの同期が難しくなる
  3. 誤って元のファイルを編集してしまうリスクがある

全体図

sites-available/ (設定の倉庫)
    |
    +--- site1.conf (スイッチOFF)
    |
    +--- site2.conf (スイッチOFF)
    |
    +--- site3.conf (スイッチOFF)

sites-enabled/ (アクティブな設定)
    |
    +--- site1.conf -> ../sites-available/site1.conf (スイッチON)
    |
    +--- site2.conf -> ../sites-available/site2.conf (スイッチON)

大規模環境のディレクトリ構造例

/etc/nginx/
│
├── nginx.conf
│
├── conf.d/
│   ├── global-settings.conf
│   ├── ssl-params.conf
│   └── ...
│
├── sites-available/
│   ├── site001.conf
│   ├── site002.conf
│   ├── site003.conf
│   │   ...
│   └── site100.conf
│
└── sites-enabled/
    ├── site001.conf -> ../sites-available/site001.conf
    ├── site002.conf -> ../sites-available/site002.conf
    ├── site003.conf -> ../sites-available/site003.conf
    │   ...
    └── site100.conf -> ../sites-available/site100.conf

結論:
Nginxにおけるシンボリックリンクの使用は、大規模なWebホスティング環境での設定管理を大幅に簡素化。これにより、管理者は迅速かつ安全にWebサイトの追加、削除、テスト、および維持を行うことが可能。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?