Fedora 37
Sponsored Link

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

 
一般ユーザーが自身のホームディレクトリ内に置いたファイルを Web サイトとして公開できるよう設定します。
[1] Nginx の設定です。設定を追加したいサイト定義の [server] セクション内に追記します。
[root@www ~]#
vi /etc/nginx/conf.d/ssl.conf
# [server] セクション内に追記

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

[root@www ~]#
systemctl reload nginx

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

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

[fedora@www ~]$
mkdir ~/public_html

[fedora@www ~]$
chmod 755 ~/public_html

[fedora@www ~]$
vi ~/public_html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div>
</body>
</html>
関連コンテンツ