openSUSE Leap 16

Nginx : ユーザーのホーム領域を有効にする2025/11/26

 

一般ユーザーが自身のホームディレクトリ内に置いたファイルを Web サイトとして公開できるよう設定します。

[1] Nginx の設定です。設定を追加したいサイト定義の [server] セクション内に追記します。
www:~ #
vi /etc/nginx/conf.d/ssl.conf
# [server] セクション内に追記

server {
    .....
    .....
    location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html$2;
        index  index.html index.htm;
    }

www:~ #
systemctl reload nginx

[2] SELinux を有効にしている場合は、ブール値の変更が必要です。
www:~ #
setsebool -P httpd_enable_homedirs on

[3] 任意の一般ユーザーで自身のホームディレクトリにテストページを作成し、動作確認をします。 作成したテストページに Web アクセスして、ページが表示されれば OK です。
suse@www:~>
chmod 711 /home/$(whoami)

suse@www:~>
mkdir ~/public_html

suse@www:~>
chmod 755 ~/public_html

suse@www:~>
vi ~/public_html/index.html
<html>
<body>
<h1 style="width: 100%; font-size: 48px; text-align: center;">
Nginx UserDir Test Page
</h1>
</body>
</html>
関連コンテンツ