Skip to content

Rocky Linux8 + Nginx + PHP 8.1 + h5ai で DirectoryIndex を見栄え良くする

以前に Nginx 関連で下記のメモを書きました。

今回は Rocky Linux 8 上の Nginx と PHP 8.1 環境へ、更に h5ai をインストールして DirectoryIndex の見栄えを改善してみましたので、手順をメモしておきます。 Nginx と PHP をインストールするまでの手順は過去のメモと同じです。

Nginx のインストール

Nginx をインストールします。

1
2
dnf config-manager --add-repo https://s3.sig9.org/repos/nginx.repo
dnf install -y nginx

PHP のインストール

remi から PHP をインストールします。 敢えて現時点で最新のバージョン 8.1 をインストールしてみました。

1
2
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf -y install php81

php-fpm の設定

php-fpm の設定ファイルは /etc/opt/remi/php81/php-fpm.d/www.conf にあります。 ユーザやグループ等の設定を書き換えます。 デフォルトでは listen.acl_users で POSIX ACL が有効になっていた為、これを無効化して listen.ownerlisten.group を利用出来るようにしています。

1
2
3
4
5
6
sed -i -e "s/^user = apache/user = nginx/g" /etc/opt/remi/php81/php-fpm.d/www.conf
sed -i -e "s/^group = apache/group = nginx/g" /etc/opt/remi/php81/php-fpm.d/www.conf
sed -i -e "s/^;listen.owner = nobody/listen.owner = nginx/g" /etc/opt/remi/php81/php-fpm.d/www.conf
sed -i -e "s/^;listen.group = nobody/listen.group = nginx/g" /etc/opt/remi/php81/php-fpm.d/www.conf
sed -i -e "s/^;listen.mode = 0660/listen.mode = 0660/g" /etc/opt/remi/php81/php-fpm.d/www.conf
sed -i -e "s/^listen.acl_users = apache/;listen.acl_users = apache/g" /etc/opt/remi/php81/php-fpm.d/www.conf

デフォルトの index.html を削除する

Nginx をインストールした直後はドキュメントルート直下に 50x.htmlindex.html が保存されています。 h5ai を使いやすくする為にデフォルトの index.html は削除しておきます。

1
rm -f /usr/share/nginx/html/index.html

Apach 風ドキュメントルートのリンクを追加する

Apache 風にドキュメントルートとして /var/www/html も使えるようにシンボリックリンクを作成します。

1
2
3
mkdir -p /var/www/
rm -rf /var/www/html/
ln -s /usr/share/nginx/html /var/www/

Nginx の設定

Nginx の設定ファイルのうち、/etc/nginx/conf.d/default.conf を以下のように修正します。 拡張子 .php のファイルは UNIX ソケット経由で php-fpm へ転送します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
cat << 'EOF' > /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

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

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        root           /usr/share/nginx/html;
        fastcgi_pass   unix:/var/opt/remi/php81/run/php-fpm/www.sock;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}
EOF

Nginx と php-fpm の起動

ここまでの準備が完了したら Nginx と php-fpm を起動&自動起動設定します。

1
2
systemctl start nginx.service php81-php-fpm.service
systemctl enable nginx.service php81-php-fpm.service

h5ai のインストール

公式サイトから h5ai をダウンロードし、ドキュメントルート配下にコピーします。 h5ai の基本的なインストール手順はこれだけです。

1
2
curl -O https://release.larsjung.de/h5ai/h5ai-0.30.0.zip
unzip h5ai-0.30.0.zip -d /usr/share/nginx/html/

ブラウザでアクセス

ブラウザで http://ADDRESS/ へアクセスすると以下のように h5ai の画面が表示されます。

file

h5ai で検索機能を有効化する

h5ai を /usr/share/nginx/html/ 配下にインストールした場合、h5ai の設定ファイルは /usr/share/nginx/html/_h5ai/private/conf/options.json に存在します。 このファイルをカスタマイズすることにより h5ai の振る舞いを変更出来ます。 今回は検索機能を有効化してみます。 options.json を以下のように変更します。

変更前

1
2
3
4
5
6
    "search": {
        "enabled": false,
        "advanced": true,
        "debounceTime": 300,
        "ignorecase": true
    },

変更後

"enabled": true, へ変更します。

1
2
3
4
5
6
    "search": {
        "enabled": true,
        "advanced": true,
        "debounceTime": 300,
        "ignorecase": true
    },

検索機能を有効化すると h5ai の画面右上に虫眼鏡アイコンが表示され、これをクリックするとキーワード検索が出来るようになります。

file

参考

デフォルトの _h5ai/private/conf/options.json

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/* h5ai v0.30.0 - https://larsjung.de/h5ai/ */
{
    /*
    Password hash.

    SHA512 hash of the info page password, the preset password is the empty string.
    Online hash generator: http://md5hashing.net/hashing/sha512
    */
    "passhash": "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e",



    /*
    Resources.

    Additional script and style tags added to all pages. Paths not beginning
    with "http://", "https://" or "/" will be looked up relative to
    "_h5ai/public/ext/" (no check for existence).

    - scripts: array of strings
    - styles: array of strings
    */
    "resources": {
        "scripts": [],
        "styles": [
            "//fonts.googleapis.com/css?family=Ubuntu:300,400,700%7CUbuntu+Mono:400,700"
        ]
    },



    /*
    General view options.

    - binaryPrefix: boolean, set to true uses 1024B=1KiB when formatting file sizes (see http://en.wikipedia.org/wiki/Binary_prefix)
    - disableSidebar: boolean, hides sidebar and toggle button
    - fallbackMode: boolean, serve fallback mode
    - fastBrowsing: boolean, use History API if available (no need to reload the whole page)
    - fonts: array of strings, fonts to use in regular context
    - fontsMono: array of strings, fonts to use in monopspaced context
    - hidden: array of strings, don't list items matching these regular expressions
    - hideFolders: boolean, hide all folders in the main view
    - hideIf403: boolean, hide files and folders that are not readable by the server
    - hideParentFolder: boolean, hide parent folder links in the main view
    - maxIconSize: number, max size for icons in the main view
    - modes: array of strings, subset of ["details", "grid", "icons"]
        the first value indicates the default view mode. If only one value
        is given the view mode is fixed and the selector buttons are hidden.
        The user selected view mode is also stored local in modern browsers
        so that it will be persistent.
    - modeToggle: boolean, show a view mode toggle in the toolbar, or "next"
    - setParentFolderLabels: boolean, set parent folder labels to real folder names
    - sizes: array of numbers
        the first value indicates the default view size. If only one value
        is given the view size is fixed and the selector buttons are hidden.
        The user selected view size is also stored local in modern browsers
        so that it will be persistent.
    - theme: string, name of one of the folders in "_h5ai/public/images/themes", defaults to "default"
    - unmanaged: array of strings, don't manage folders containing one of those files
    - unmanagedInNewWindow: boolean, open unmanaged links in new window/tab
    */
    "view": {
        "binaryPrefix": false,
        "disableSidebar": false,
        "fallbackMode": false,
        "fastBrowsing": true,
        "fonts": ["Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif"],
        "fontsMono": ["Ubuntu Mono", "Monaco", "Lucida Sans Typewriter", "monospace"],
        "hidden": ["^\\.", "^_h5ai"],
        "hideFolders": false,
        "hideIf403": true,
        "hideParentFolder": false,
        "maxIconSize": 40,
        "modes": ["details", "grid", "icons"],
        "modeToggle": false,
        "setParentFolderLabels": true,
        "sizes": [20, 40, 60, 80, 100, 140, 180, 220, 260, 300],
        "theme": "comity",
        "unmanaged": ["index.html", "index.htm", "index.php"],
        "unmanagedInNewWindow": false
    },



    /*** Extensions (in alphabetical order) ***/

    /*
    Watch and update current folder content.

    - interval: number, update interval in milliseconds, at least 1000
    */
    "autorefresh": {
        "enabled": false,
        "interval": 5000
    },

    /*
    Show a clickable breadcrumb.
    */
    "crumb": {
        "enabled": true
    },

    /*
    Allow customized header and footer files.
    First checks for files "_h5ai.header.html" and "_h5ai.footer.html" in the current directory.
    If not successful it checks all parent directories (starting in the current directory) for
    files "_h5ai.headers.html" and "_h5ai.footers.html".
    Note the different filenames: "header" (only current) - "headers" (current and sub directories)!
    The file's content will be placed inside a <div/> tag above/below the main content.
    If a file's extension is ".md" instead of ".html" its content will be interpreted as markdown.

    - stopSearchingAtRoot: boolean, only search for header and footer files until the web root
        directory. if `false`, will search for header/footer up the entire directory structure,
        even above the web root
    */
    "custom": {
        "enabled": true,
        "stopSearchingAtRoot": true
    },

    /*
    Enable packaged download of selected entries.
    To select files the "select"-extension needs to be enabled.

    - type: string, "php-tar", "shell-tar" or "shell-zip"
    - packageName: string, basename of the download package, null for current filename or foldername
    - alwaysVisible: boolean, always show download button (defaults to download the current folder)
    */
    "download": {
        "enabled": true,
        "type": "php-tar",
        "packageName": null,
        "alwaysVisible": false
    },

    /*
    Allow filtering the displayed files and folders in current folder.
    Checks for substrings.

    If advanced is enabled it checks entries for right order of characters,
    i.e. "ab" matches "ab", "axb", "xaxbx" but not "ba". Space separated
    sequences get OR-ed. Searches will be treated as JavaScript regular
    expressions if you prefix them with "re:".

    - advanced: boolean, use advanced pattern parsing
    - debounceTime: number, debounce wait time in milliseconds
    - ignorecase: boolean, ignore case
    */
    "filter": {
        "enabled": false,
        "advanced": true,
        "debounceTime": 100,
        "ignorecase": true
    },

    /*
    Calc the size of folders.
    This operation is real slow. The calculated sizes differ slightly for both
    calculation types since "php" only adds the file size, while "shell-du"
    also adds the sizes for the actual folder files.

    - type: string, "php" (sloooow) or "shell-du" (sloow)
    */
    "foldersize": {
        "enabled": true,
        "type": "php"
    },

    /*
    Adds Google Universial Analytics asynchronous tracking code.
    see: https://developers.google.com/analytics/devguides/collection/analyticsjs/

    - id: string, account ID
    */
    "google-analytics-ua": {
        "enabled": false,
        "id": "UA-000000-0"
    },

    /*
    Enable a generic info side bar.

    - show: boolean, initial visible to first time users
    - qrcode: boolean, show a QR-Code
    - qrColor: string, QR-Code fill color
    */
    "info": {
        "enabled": true,
        "show": false,
        "qrcode": true,
        "qrFill": "#999",
        "qrBack": "#fff"
    },

    /*
    Localization, for example "en", "de" etc. - see "_h5ai/conf/l10n" folder for
    possible values. Adjust it to your needs. If lang is not found
    it defaults to "en".

    - lang: string, default language
    - useBroserLang: boolean, try to use browser language
    */
    "l10n": {
        "enabled": true,
        "lang": "en",
        "useBrowserLang": true
    },

    /*
    Adds Piwik tracker javascript code.

    - baseURL: string, do not include the protocol, e.g. "mydomain.tld/piwik"
    - idSite: number
    */
    "piwik-analytics": {
        "enabled": false,
        "baseURL": "some/url",
        "idSite": 1
    },

    /*
    Play a audio preview on click.

    - autoplay: start playing as soon as ready
    - types: array of strings
    */
    "preview-aud": {
        "enabled": true,
        "autoplay": true,
        "types": ["aud"]
    },

    /*
    Show an image preview on click.

    - types: array of strings
    - size: number, sample size, or false for original size
    */
    "preview-img": {
        "enabled": true,
        "size": false,
        "types": ["img", "img-bmp", "img-gif", "img-ico", "img-jpg", "img-png", "img-raw", "img-svg"]
    },

    /*
    Show text file preview on click.

    Available styles are:
      0: floating text
      1: fixed width text
      2: markdown
      3: syntax highlighting

    - styles: dict string to int, maps types to styles
    */
    "preview-txt": {
        "enabled": true,
        "styles": {
            "txt": 1,
            "txt-authors": 1,
            "txt-c": 3,
            "txt-cpp": 3,
            "txt-css": 3,
            "txt-diff": 1,
            "txt-go": 3,
            "txt-h": 3,
            "txt-hpp": 3,
            "txt-install": 1,
            "txt-js": 3,
            "txt-json": 3,
            "txt-less": 3,
            "txt-license": 1,
            "txt-log": 1,
            "txt-makefile": 1,
            "txt-md": 2,
            "txt-py": 3,
            "txt-rb": 3,
            "txt-readme": 1,
            "txt-rtf": 1,
            "txt-rust": 3,
            "txt-script": 3,
            "txt-xml": 1
        }
    },

    /*
    Play a video preview on click.

    - autoplay: start playing as soon as ready
    - types: array of strings
    */
    "preview-vid": {
        "enabled": true,
        "autoplay": true,
        "types": ["vid-avi", "vid-flv", "vid-mkv", "vid-mov", "vid-mp4", "vid-mpg", "vid-webm"]
    },

    /*
    Allow searching files and folders in and below current folder.
    Checks for substrings.

    If advanced is enabled it checks entries for right order of characters,
    i.e. "ab" matches "ab", "axb", "xaxbx" but not "ba". Space separated
    sequences get OR-ed. Searches will be treated as JavaScript regular
    expressions if you prefix them with "re:".

    - advanced: boolean, use advanced pattern parsing
    - debounceTime: number, debounce wait time in milliseconds
    - ignorecase: boolean, ignore case
    */
    "search": {
        "enabled": false,
        "advanced": true,
        "debounceTime": 300,
        "ignorecase": true
    },

    /*
    Make entries selectable.
    At the moment only needed for packaged download.

    - clickndrag: boolean, allow first mouse button + drag selection
    - checkboxes: boolean, show a checkbox on mouse over item
    */
    "select": {
        "enabled": true,
        "clickndrag": true,
        "checkboxes": true
    },

    /*
    Default sort order.
    "column" and "reverse" are locally stored.

    - column: number, 0 for "Name", 1 for "Date", 2 for "Size"
    - reverse: boolean, false for ascending, true for descending
    - ignorecase: boolean, compare ignorecase
    - natural: boolean, use natural sort order
    - folders: number, where to place folders, 0 for "top", 1 for "in place", 2 for "bottom"
    */
    "sort": {
        "enabled": true,
        "column": 0,
        "reverse": false,
        "ignorecase": true,
        "natural": true,
        "folders": 0
    },

    /*
    Show thumbnails for image files. Needs the "/_h5ai/public/cache" folder to be
    writable for the web Server.

    - img: array of strings
    - mov: array of strings
    - doc: array of strings
    - delay: number, delay in milliseconds after "dom-ready" before thumb-requesting starts
    - size: number, size in pixel of the generated thumbnails
    - exif: boolean, use included EXIF thumbs if possible
    - chunksize: int, number of thumbs per request
    */
    "thumbnails": {
        "enabled": true,
        "img": ["img-bmp", "img-gif", "img-ico", "img-jpg", "img-png"],
        "mov": ["vid-avi", "vid-flv", "vid-mkv", "vid-mov", "vid-mp4", "vid-mpg", "vid-webm"],
        "doc": ["x-pdf", "x-ps"],
        "delay": 1,
        "size": 240,
        "exif": false,
        "chunksize": 20
    },

    /*
    Replace window title with current breadcrumb.
    */
    "title": {
        "enabled": true
    },

    /*
    Show a folder tree.
    Note that this might affect performance significantly.

    - show: boolean, initial visible to first time users
    - maxSubfolders: number, max number of subfolders to show in tree
    - naturalSort: boolean, use natural sort order for folders
    - ignorecase: boolean, sort ignorecase
    */
    "tree": {
        "enabled": true,
        "show": true,
        "maxSubfolders": 50,
        "naturalSort": true,
        "ignorecase": true
    }
}