Debian 11 Bullseye
Sponsored Link

Nginx : ユーザーのホーム領域を有効にする2021/09/10

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

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

root@www:~#
systemctl restart nginx

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

debian@www:~$
mkdir ~/public_html

debian@www:~$
chmod 755 ~/public_html

debian@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>
関連コンテンツ