0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

webarenaでubuntu その74

0
Last updated at Posted at 2026-11-03

概要

webarenaでubuntu18.04やってみた。
vpsクラウドが終了するらしい。
vpsクラウドからindigoに引っ越す検討。
indigo申し込んでみた。
レンタルサーバーのようなバーチャルドメインを計画してみる。

レンタルサーバーのようなバーチャルドメイン

各ユーザーのホームディレクトリの中に public_html というフォルダがあり、そこをWeb公開ディレクトリ(DocumentRoot)にする構成です。

• サイトA: /home/users/user-a/public_html
• サイトB: /home/users/user-b/public_html
この構成の場合、「FTPでログインしたときはユーザーのホーム(/home/users/user-a)に入り、WEB公開データは public_html の中に入れる」 という、レンタルサーバーでよくある非常に使いやすい環境が作れます。

Step 1: adduser でユーザー作成とディレクトリ準備

まずベースとなるユーザーを作成し、その中に public_html を作成します。

# 1. user-a の作成(ホームディレクトリを /home/users/user-a に指定)
sudo adduser --home /home/users/user-a --shell /bin/false user-a

# 2. user-b の作成
sudo adduser --home /home/users/user-b --shell /bin/false user-b

# 3. 各ユーザーの中に public_html ディレクトリを作成
sudo mkdir -p /home/users/user-a/public_html
sudo mkdir -p /home/users/user-b/public_html

Apacheがアクセスできるように権限(パーミッション)を設定

Apache(www-data)が各ユーザーのホームディレクトリを通り抜けて、public_html 内のファイルを読み書きできるようにグループと権限を設定します。

# 各ユーザーを Apache グループ (www-data) に追加
sudo usermod -aG www-data user-a
sudo usermod -aG www-data user-b

# すべての所有権を正しく設定
sudo chown -R user-a:user-a /home/users/user-a
sudo chown -R user-b:user-b /home/users/user-b

# Apacheが上の階層を通過できるように、ホームの権限を「755」または「750」にする
# ※今回はグループ(www-data)に属させているので 750 でも動作します
sudo chmod 750 /home/users/user-a
sudo chmod 750 /home/users/user-b

# public_html 自体は、FTPユーザーもApacheも読み書きできるように「775」に設定
sudo chmod 775 /home/users/user-a/public_html
sudo chmod 775 /home/users/user-b/public_html

# 動作確認用のテストHTMLを作成
echo "<h1>Welcome to Site A (public_html)</h1>" | sudo tee /home/users/user-a/public_html/index.html
echo "<h1>Welcome to Site B (public_html)</h1>" | sudo tee /home/users/user-b/public_html/index.html

Step 2: Apache バーチャルホストの設定

DocumentRoot をそれぞれの public_html に指定します。
• /etc/apache2/sites-available/example-a.com.conf

<VirtualHost *:80>
    ServerName example-a.com
    DocumentRoot /home/users/user-a/public_html
    <Directory /home/users/user-a/public_html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/example-a.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example-a.com_access.log combined
</VirtualHost>

• /etc/apache2/sites-available/example-b.com.conf

<VirtualHost *:80>
    ServerName example-b.com
    DocumentRoot /home/users/user-b/public_html
    <Directory /home/users/user-b/public_html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/example-b.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example-b.com_access.log combined
</VirtualHost>

設定を反映します。

sudo apache2ctl configtest
sudo systemctl reload apache2

Step 3: vsftpd の設定

今回の構成であれば、vsftpdの個別設定(user_config_dir)は不要です。FTP接続すると自動的に各ユーザーのホームディレクトリ(/home/users/user-X)がルート(最上階層)として見え、その中に public_html フォルダがある状態になります。
/etc/vsftpd.conf の最下部が以下のようになっているか確認してください。

local_enable=YES
write_enable=YES
chroot_local_user=YES
local_umask=002
allow_writeable_chroot=YES
check_shell=NO

設定を反映します。

sudo systemctl restart vsftpd

この構成でのFTP運用のイメージ

WindowsからFileZillaなどで user-a としてログインすると、接続直後は /(実際は /home/users/user-a)に見えます。
その中に public_html というフォルダが入っているので、「public_html の中にWebサイトのデータをアップロードする」 という運用になります。

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?