nginx ファイルディレクトリ マウント設定【簡単解説】
nginxにディレクトリをマウントするには、nginxの設定ファイルにlocationディレクティブを追加して、マウントするディレクトリを指定する必要があります。
例えば、”files”という名前のファイルディレクトリをマウントする場合、nginxの設定ファイルに以下の設定を追加することができます。
server {
listen 80;
server_name example.com;
location /files {
alias /path/to/files/directory;
}
}
http://example.com/filesにアクセスすると、nginxはリクエストを/path/to/files/directoryディレクトリにマッピングします。
URL内の場所パスを残したい場合は、aliasコマンドを使用します。場所パスを削除したい場合は、rootコマンドを使用してください。
server {
listen 80;
server_name example.com;
location /files {
root /path/to/files/directory;
}
}
このように、http://example.com/files にアクセスすると、nginx はリクエストを /path/to/files ディレクトリ内のファイルにマッピングしますが、URLにはlocationのパスが残りません。