
Ubuntu
Sever Edition
を使ったサーバ構築のメモ

最終更新:2008年3月19日
リンク Debian を使ったサーバ構築のメモ
リンク 坂村酒店
リンク HB
サロン
1. はじめに
Debianを使ってサーバを構築してから3年が経ち、たまたまUSB接続のRAIDドライブを入手しましたので
Ubuntu Sever Edition を使って新たにサーバを再構築してみました
その時のメモを思い出しながら残していきます
サーバは、固定IPアドレス/独自ドメインで構成しました
いろいろなサイトを参考にさせていただきました
ありがとうございました
間違っている箇所もたくさんあると思います
これはあくまでも個人的なメモであり、この通りにやって
不具合が生じても保証の限りではありません(免
責事
項)
ご意見、ご質問がありましたら、postmaster@kazutoyo.com
へメールをいただけるとありがたいです
2. 用意するもの
1. 余っているintel系CPUを使ったノートPC
(デスクトップでも良いですが、サーバは24時間/365日稼働しますので、電気
代がばかになりません)
2. Ubuntu-7.10-server インストール CD
3. 少しばかりのやる気
4. 常時接続環境
こちらでは、3つのバーチャルドメインをサポートしています。
3つのドメインをここでは便宜上メジャーリーグにたとえて、boston.com
seattle.com newyork.com と表現しています
実在するそれぞれのドメインとは何の関係もありませんので、ご注意ください
そしてそれぞれのドメインのユーザ名を matsuzaka
ichiro matsui と表現しています
またサーバのホスト名を fenwaypark.boston.com
、サーバのIPアドレスを 192.168.0.2
と表現しています
それぞれをご自分のドメイン名、ユーザ名に読み替えてください
3. Ubuntu-7.10-server のインストール
http://www.ubuntu.com/getubuntu/download
から
ubuntu-7.10-server-i386.iso
をダウンロードして、CD-ROMにISO形式で焼きます。
次に、PCをこのCD-ROMから起動させてインストールしていきます。
インストールでは質問に答える形で設定を行って行きます。
以下の順番でインストール作業を進めて行きます。
1. F2キーで日本語を選択します
2. 「ハードディスクにインストール」を選択します
3. Control+Shift を選択します(適時変更してください)
4. ホスト名に サーバのホスト名 を入力します
5. 「ディスク全体を使う」を選択します(適時変更
してください)
6. SCSI1 (sda) を選択します (適時変更してください)
7. ディスクに変更を書き込みますか? 「はい」を選択します
8. システム時間を UTF に設定していますか? 「いいえ」を選択します
9. 新しいユーザの本名(フルネーム):ユーザ名を入力します
10. あなたのアカウントのユーザ名:ユーザ名を入力します
11. 新しいユーザのパスワードを選んでください: パスワードを入力します
12. 確認のため、再度パスワードを入力してください: パスワードを入力します
13. Software selection
[*] DNS sever
[*] LAMP server
[*] Mail server
[*] OpenSSH server
[ ] PostgreySQL database
[*] Print server
[*] Samba File server
を選択します
14. New password for the MySQL "root" user:
MySQLのrootのパスワードを入力します
15. メール設定の一般形式:「インターネットサイト」を選択します
16. システムメール名: 例)
「boston.com」を入力
します
17. インストール完了 「続ける」を選択します
ここで再起動させると...
PANIC:CPU too old for this kernel.
のエラーメッセージが出ました。
この場合、CDをもう一度入れてCDから起動させます。
1. F2キーで日本語を選択します
2. 「壊れたシステムをレスキュー」 を選択します
3 〜 4 は同様に
5. レスキューモードに移行 /dev/sda1 を選択します (適時変更してください)
6. /dev/sda1 内でシェルを実行します
7. 続ける を選択します
# apt-get update
# apt-get install linux-generic
# apt-get remove linux-server
# exit
8. 「システムの再起動」を選択します
再起動後、Grubの画面で kernel-2.6.22-generic で起動させます
再起動させたら、すぐに menu.list を書き換えて置きます
# vi /boot/grub/menu.lst
デフォルトで generic のカーネルで起動するように下記の様に変更します
# You can specify 'saved' instead of a number. In
this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use
'savedefault' or your
# array will desync and will not let you boot your
system.
default
0 → 2
にしておきます (generic
なカーネルで起動するように適時変更してください)
4. ネットワークの設定
次に、ネットワークの設定を行います。
# vi /etc/network/interfaces
以下の設定にします。 ここでは、サーバのIPアドレスが 192.168.0.2
の場合です
# This file describes the network interfaces
available on your system
# and how to activate them. For more information,
see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.2 (適時変
更してください)
netmask 255.255.255.0 (適時
変更してください)
network 192.168.0.0 (適時変
更してください)
broadcast 192.168.0.255(適
時変更してください)
gateway 192.168.0.1 (適時変
更してください)
ここで再起動させておきます
# reboot
リモートのPCでSSHで接続させるときにサーバのIPアドレスが古いサーバと同じIPアドレスの場合は接続出来ません。
その場合は、SSHのknown_hosts をクリアしてアクセスすると接続できるようになります
5. BINDの設定
ネームサーバはドメインを取得した GANDI(https://www.gandi.net/domain/transfer/?lang=en)
で設定していますので、ここでは
外向きの設定のみ行います
# vi /etc/bind/named.conf.options
forwarderの部分をコメントアウトしてISPのネームサーバを設定しておきます
以下は Asahi-net さんのネームサーバの場合です (ご自
分の契約されているISPのネームサーバのアドレスを適時設定してください)
forwarders {
202.224.32.1; (適時変更してく
ださい)
202.224.32.2; (適時変更してく
ださい)
};
逆引きゾーンの設定をしておきます
# vi /etc/bind/db.192.168.0
$TTL 604800
@
IN
SOA localhost.
root.localhost. (
2007112701
; Serial
604800
; Refresh
86400
; Retry
2419200
; Expire
604800 ) ;
Negative Cache TTL
;
@
IN
NS
fenwaypark.boston.com. (適
時変更してください)
2
IN
PTR localhost. (適時変更してください)
2
IN
PTR fenwaypark.boston.com. (適時変更してください)
# vi /etc/bind/named.conf.local
に以下の設定を追加します
zone "boston.com" {
(適時変更してください)
type master;
file "/etc/bind/db.boston.com"; (適時変更してください)
};
zone "seatlle.com" {
(適時変更してください)
type master;
file "/etc/bind/db.seattle.com";
(適
時変更してください)
};
zone "newyork.com" {
(適時変更してください)
type master;
file "/etc/bind/db.newyork.com";
(適
時変更してください)
};
zone "0.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168.0";
};
次にそれぞれのドメインの zoneファイルを作っておきます。
# vi /etc/bind/db.boston.com
;
; BIND reverse data file for boston.com zone
;
$TTL 604800
@
IN
SOA localhost.
root.localhost. (
2007112701
; Serial
604800
; Refresh
86400
; Retry
2419200
; Expire
604800 ) ;
Negative Cache TTL
;
IN
NS
fenwaypark.boston.com.
fenwaypark
IN
A
192.168.0.2 (適時
変更してください)
www
IN
A
192.168.0.2
(適
時変更してください)
ftp
IN
A
192.168.0.2
(適
時変更してください)
smtp
IN
A
192.168.0.2
(適
時変更してください)
pop
IN
A
192.168.0.2
(適
時変更してください)
mail
IN
A
192.168.0.2
(適時変更してください)
それぞれのドメイン用の zoneファイルはメインドメインの boston.com と同じですので、コピーして使います
# cp /etc/bind/db.boston.com
/etc/bind/db.seattle.com (適
時変更してください)
# cp /etc/bind/db.boston.com
/etc/bind/db.newyork.com (適
時変更してください)
ここで、BINDを再起動させておきます
# /etc/init.d/bind9 restart
6. メールサーバの設定
メールサーバは postfix / postfixadmin / dovecot / MySQL / Cyrus-sasl2
を使って構築し、通信はSSL暗号化を行います
ubuntu server edition では、postfix/dovecot/MySQL
はンストール時に選択しているので、すでにインストールされています
それぞれのドメイン boston.com
、seatlle.com 、newyork.com をバーチャルドメインとしてサポートします
6-1 postfixadmin の設定
まずメールユーザのアカウントの設定をWebで簡単に行えるように postfixadmin をインストールします
http://sourceforge.net/projects/postfixadmin/
から postfixadmin-2.1.0.tgz
をダウンロードします
ここでは、/var/www/ にダウンロードしたものとして進めます
# cd /var/www
# tar zxvf postfixadmin-2.1.0.tgz
設定用のファイルは、サンプルの設定ファイル config.inc.php.sample をコピーして使用します
# cd /var/www/postfixadmin/
# cp config.inc.php.sample config.inc.php
# chown www-data:www-data config.inc.php
# chmod 640 config.inc.php
http://192.168.0.2/postfixadmin/
でアクセスし、setup をクリックしてみてエラーがないことを確認します
エラーがなかったら、setupファイルを削除しておきます
# rm setup.php
用意されているスクリプトをコピーしてMySQLのテーブルを作成します
# cd /var/www/postfixadmin
# mysql -u root -p < DATABASE_MYSQL.TXT
Enter password: ← MySQLのrootの
パスワードを入力します
ここで一度ブラウザで確認しておきます
http://192.168.0.2/postfixadmin/admin/
画面上でいずれかのメニューをクリックすると
To remove this text,
delete the motd-admin.txt file.
と表示されるので、以下のファイルをそれぞれリネームしておきます
# cd /var/www/postfixadmin
# mv motd.txt motd.org.txt
# mv motd-admin.txt motd.org-admin.txt
# mv motd-users.txt motd.org-users.txt
画面上に表示されるドメイン名等を自分のドメイン用に修正します
# cd /var/www/postfixadmin
# sed -i
"s/\@change-this-to-your.domain.tld/\@boston.com/g" config.inc.php
# sed -i
"s/change-this-to-your.domain.tld/boston.com/g" config.inc.php
# sed -i "s/Return to boston.com/Return to
www.boston.com/g" config.inc.php
postfixadmin のwebでの表示が英語なので、表示の日本語化を行います
こちらのサイト (http://www.aconus.com/~oyaji/suse9.2/smtp-mysql-suse.htm)
の日本語用ファイルを使用させていただきました
ありがとうございました
# cd /var/www/postfixadmin/languages
# wget http://www.aconus.com/~oyaji/suse9.2/ja.lang
# chown www-data:www-data ja.lang
# chmod 640 ja.lang
# cd ../
# sed -i "s/\$CONF\['default_language'\] =
'en'/\$CONF\['default_language'\] = 'ja'/g" config.inc.php
# cd ./templates
# sed -i "s/iso-8859-1/Shift_JIS/g" header.tpl
他人からアクセスされては困るのでベーシック認証を設定しておきます
# cd /var/www/postfixadmin/admin
#
sed -i
"s/\/usr\/local\/www\/<domain.tld>\/admin\/.htpasswd/\/var\/www\/postfixadmin\/admin\/.htpasswd/g"
.htaccess
ベーシック認証のパスワードを設定します
# cd /var/www/postfixadmin/admin
# htpasswd -c .htpasswd matsuzaka
(適時変更してください)
New password: ← パスワードを入力し
ます
Re-type new password: ← 確認のため
同じパスワードを入力します
Adding password for user matsuzaka
.htpasswd が使えるようにapache2の設定を追加します
# vi /etc/apache2/apache2.conf
一番最後に以下の設定を追加しておきます
<Directory
/var/www/postfixadmin/admin>
AllowOverride
AuthConfig
</Directory>
パスワードが使えるように apache2 を再起動させておきます
# /etc/init.d/apache2 restart
次に、postfixadminのパスワードを変更します
# mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor. Commands
end with ; or \g.
Your MySQL connection id is 115
Server version: 5.0.45-Debian_1ubuntu3-log Debian
etch distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> set password for postfix@'localhost'=password('matsuzaka');
← 適時変更してくだ
さい
Query OK, 0 rows affected (0.00 sec)
mysql> set password for
postfixadmin@'localhost'=password('matsuzaka');
← 適時変更してください
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
postfixadmin のパスワードも同じパスワードに変更しておきます
# cd /var/www/postfixadmin/
# sed -i "s/\$CONF\['database_password'\] =
'postfixadmin'/\$CONF\['database_password'\] = 'matsuzaka'/g"
config.inc.php ← 適時変更
してください
パスワード体系をmd5cryptからcleartextへ変更します
SSL暗号化するため、平文で問題ないと思います
# cd /var/www/postfixadmin/
# sed -i "s/'md5crypt'/'cleartext'/g" config.inc.php
メールの格納場所を変更できるように設定しておきます
# cd /var/www/postfixadmin/
# vi config.inc.php
$CONF['domain_path'] = 'NO'; を 'YES'
に変更します
6-2 postfix の設定
次に、メールサーバ本体の postfix の設定を行います
最初に alias の設定をしておきます
# vi /etc/aliases
以下を追加しておきます
root: matsuzaka@boston.com
← rootのアドレスです。適時変
更してください
postmaster: root
mailer-daemon: postmaster
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
次に、メールのユーザを管理するデータベースを使うために、postfix-mysql をインストールします
# apt-get install postfix-mysql
バーチャルドメインで動作させる場合の専用ユーザとグループおよびメールボックス用のディレクトリを
作成しておきます。
ここではバーチャルドメインのユーザ名は vuser としています
メールの保存場所は、 /home/virtual/boston.com/matsuzaka の様になります
# groupadd -g 10000 vuser
# useradd -g vuser -u 10000 vuser
# mkdir /home/virtual
# chown vuser:vuser /home/virtual
# chmod 771 /home/virtual
次に、postfix のメインの設定ファイルである main.cf を設定していきます
以下はこちらの main.cf の設定例です
postgrey や SASL や SSL の設定は後述します
内容は適時変更してください
# See /usr/share/postfix/main.cf.dist for a
commented, more complete version
# Debian specific: Specifying a file name
will cause the first
# line of that file to be used as the
name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
# TLS parameters
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_cert_file=/etc/ssl/Server/cert.pem
smtpd_tls_key_file=/etc/ssl/Server/mail.pem
smtpd_use_tls=yes
smtpd_tls_session_cache_database =
btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database =
btree:${queue_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc
package for
# information on enabling SSL in the smtp client.
main = boston.com
← 適時変更してくだ
さい
myhostname = fenwaypark.boston.com
← 適時変更してくだ
さい
mydomain = boston.com
← 適時変更してくだ
さい
myorigin
= $myhostname
inet_interfaces = all
mydestination =
mynetworks = 192.168.0.0/24, 127.0.0.0/8
relay_domains = $mydestination
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
local_transport = virtual
virtual_transport = virtual
virtual_mailbox_base = /home/virtual
virtual_alias_maps =
proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_alias_domains = $virtual_alias_maps
virtual_mailbox_domains =
proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps =
proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 10000
virtual_uid_maps = static:10000
virtual_gid_maps = static:10000
content_filter=smtp-amavis:[127.0.0.1]:10024
# ここからは SASL の設定です
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = boston.com
← 適時変更してくだ
さい
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks,
permit_auth_destination, permit_sasl_authenticated, reject
broken_sasl_auth_clients = yes
# ここからは SPAM 対策です
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
permit_auth_destination
reject_unauth_destination
check_client_access
regexp:/etc/postfix/permit_client_nots25r
check_policy_service inet:60000
permit
smtpd_data_restrictions =
permit_mynetworks
permit_sasl_authenticated
check_client_access
regexp:/etc/postfix/permit_client_nots25r
check_policy_service inet:60000
permit
# ブラックリストの設定をします
smtpd_client_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
reject_invalid_hostname
reject_rbl_client bl.spamcop.net
reject_rbl_client sbl-xbl.spamhaus.org
permit
# 送れないプロバイダは別の経路で送ります
transport_maps = hash:/etc/postfix/transport
# ここからは soft quota の設定です
mailbox_size_limit = 51200000
message_size_limit = 10240000
virtual_mailbox_limit = 51200000
virtual_mailbox_limit_maps =
hash:/etc/postfix/vquota
virtual_mailbox_limit_override = yes
virtual_overquota_bounce = yes
virtual_mailbox_limit_inbox = yes
次にメールのユーザを管理する MySQL の認証用のファイルを作ります
# cd /etc/postfix
# vi mysql_virtual_alias_maps.cf
user = postfix
password = matsuzaka
← MySQL のパスワードです。 適時変更してくだ
さい
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
# vi mysql_virtual_domains_maps.cf
user = postfix
password = matsuzaka
← MySQL のパスワードです。 適時変更してくだ
さい
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
# vi mysql_virtual_mailbox_maps.cf
user = postfix
password = matsuzaka
← MySQL のパスワードです。 適時変更してくだ
さい
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
ここでパーミッションを変更しておきます
# chmod 644 /etc/postfix/mysql_virtual*
以下のワーニングがでる場合は、ドメイン名を同じにしないようにしてください
warning: do not list domain fenwaypark.boston.com
in BOTH mydestination and virtual_mailbox_domains
ここで、一度 postfix を再起動させておきます
# /etc/init.d/postfix restart
6-3 dovecot の設定
次に、imap や pop3 でサーバからメールを読み出すための dovecot を設定していきます。
最初に dovecot の設定ファイル dovecot.conf を編集します
# cd /etc/dovecot
# vi dovecot.conf
protocols = imap imaps pop3 pop3s ← 通信はSSL暗号化するため、imaps と pop3s が必要です
#ssl_disable = no
ssl_disable = no
← 通信は
SSL暗号化をするためコメントアウトを外しておきます
mail_location =
maildir:/home/virtual/%d/%u ←
メールの格納場所は、/home/virtual/boston.com/matsuzaka
の様にするため追加し
ておきます
また、パスワード認証は pam を使いませんので以下をコメントアウトしておきます
# passdb pam {
・・・
・・・
# }
パスワードのデータベースは、MySQLデータベースをユーザ管理用に使用するため以下を追加しておきます
passdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
dovecot の MySQL用設定ファイル dovecot-mysql.conf を設定します
サンプルの dovecot-sql-example.conf をコピーして作成します
# cd /etc/dovecot/
# cp dovecot-sql-example.conf dovecot-mysql.conf
# vi dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix
user=postfix password=matsuzaka
←MySQL のパスワードです。適時変更してくだ
さい
default_pass_scheme
= PLAIN
password_query = SELECT password FROM mailbox WHERE
username = '%u' AND active = '1'
user_query
= SELECT concat('/home/virtual/', maildir) as home, 10000 as uid, 10000
as gid FROM mailbox WHERE username = '%u' AND active = '1'
ここで dovecot を再起動させておきます
# /etc/init.d/dovecot restart
dovecot は時間に厳しいため、サーバの時計の時間が逆戻りすると
Nov
30 23:36:48 fenwaypark dovecot: Time just moved backwards by 31
seconds. This might cause a lot of problems, so I'll just kill myself
now. http://wiki.dovecot.org/TimeMovedBackwards
と言って自らを kill してしまいます。
知らないうちにメールが読めなくなってしまいますので、定期的に ntpdate で時間を正しく合わせることをおすすめします。
6-4 SSLの設定
メールやWebをSSL暗号化するために、openssl の設定を行います
こちらのサイトを参考にさせていただきました
http://nai.homelinux.net/ssl.html
SSL証明書は高くて買えないので、自分で自分を証明する「オレオレ」証明書を使用します
「オレオレ」と言っても詐欺ではありません
最初に何度も聞かれるデフォルトの項目を設定をしておきます
# vi /etc/ssl/openssl.cnf
default_days
=
3650
# how long to certify for 有
効期間を 365 → 3650 10年に変更しておきます
#dir
=
./demoCA
# Where everything is kept
dir
=
/etc/ssl/CA
# Where everything is kept ディレクトリ
を変更しておきます
countryName_default
= AU ← JPに変更しておきます
stateOrProvinceName_default
= Some-State ←
Kanagawa に変更しました
localityName_default
= Yokohama ←
追加しました
0.organizationName_default
= Internet Widgits Pty Ltd ←
Private に変更しました
organizationalUnitName_default = matsuzaka
← コメントアウトを外して、
matsuzaka を追加します
commonName_default
= matsuzaka.boston.com
← 追加します
emailAddress_default
= matsuzaka@boston.com
← 追加
します
[ usr_cert ]
# This is OK for an SSL server.
#
nsCertType
= server
nsCertType
= server
← コメントアウトを外します
[ v3_ca ]
# Some might want this also
# nsCertType = sslCA, emailCA
nsCertType = sslCA, emailCA
← コメントアウトを外しま
す
次に必要な各種ディレクトリ、ファイルを作っておきます
# cd /etc/ssl
# mkdir CA
# cd /etc/ssl/CA
# cat /dev/null > index.txt
# echo '01' > serial
# echo '01' > crlnumber
# mkdir private
# chmod 700 private
# mkdir newcerts
# mkdir crl
# mkdir certs
まず、秘密鍵を作ります
# openssl genrsa -out private/cakey.pem 1024
Generating RSA private key, 1024 bit long modulus
.....++++++
................................++++++
e is 65537 (0x10001)
秘密鍵を使って証明書を作成します
-daysオプションで有効期限を10年と設定しておきます
# openssl req -new -x509 -days 3560 -key
private/cakey.pem -out cacert.pem
You are about to be asked to enter information that
will be incorporated
into your certificate request.
What you are about to enter is what is called a
Distinguished Name or a DN.
There are quite a few fields but you can leave some
blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name)
[Some-State]:Kanagawa
Locality Name (eg, city) []:Yokohama
Organization Name (eg, company) [Internet Widgits
Pty Ltd]:Private
Organizational Unit Name (eg, section) []:matsuzaka
Common Name (eg, YOUR name)
[]:fenwaypark.boston.com
Email Address []:matsuzaka@boston.com
サーバ証明書を作ります
サーバ証明書作成はまず署名リクエスト(CSR)を作成し、それをCAで署名して作ります
場所は /etc/ssl/Server にします
# mkdir /etc/ssl/Server
# cd /etc/ssl/Server
秘密鍵を作ります
# openssl genrsa -out private.pem 1024
Generating RSA private key, 1024 bit long modulus
..............++++++
..++++++
e is 65537 (0x10001)
認証局に署名してもらう為リクエストを作成する必要します
# openssl req -new -key private.pem -out request.pem
You are about to be asked to enter information that
will be incorporated
into your certificate request.
What you are about to enter is what is called a
Distinguished Name or a DN.
There are quite a few fields but you can leave some
blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name)
[Some-State]:Kanagawa
Locality Name (eg, city) []:Yokohama
Organization Name (eg, company) [Internet Widgits
Pty Ltd]:Private
Organizational Unit Name (eg, section) []:matsuzaka
Common Name (eg, YOUR name) []:fenwaypark.boston.com
Email Address []:matsuzaka@boston.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
←
エンターを入力します
An optional company name []:
← エンターを入力します
CAで署名します
# cp /etc/ssl/openssl.cnf ./.
# openssl ca -config openssl.cnf -policy policy_anything -out
./cert-ca.pem -infiles request.pem
Using configuration from openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Nov 17 12:21:52 2007 GMT
Not After : Nov 14 12:21:52 2017 GMT
Subject:
countryName
= JP
stateOrProvinceName
= Kanagawa
localityName
= Yokohama
organizationName
= Private
organizationalUnitName = matsuzaka
commonName
= fenwaypark.boston.com
emailAddress
= matsuzaka@boston.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Cert Type:
SSL Server
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
2A:8C:E5:1F:7B:C9:E6:A2:9F:EE:EF:13:F1:70:24:D0:3B:1C:E8:AB
X509v3 Authority Key Identifier:
keyid:73:11:5D:84:26:74:9B:11:BD:F4:46:A3:77:1B:8F:2C:8B:F3:EB:8C
Certificate is to be certified until Nov 14 12:21:52 2017 GMT
(3650 days)
Sign
the certificate? [y/n]:y
← y と入力します
1 out of 1 certificate requests certified, commit?
[y/n]y ← y と入力します
Write out database with 1 new entries
Data Base Updated
メールサーバ用の証明書はサーバ証明書だけ抜き取ります
# openssl x509 -in cert-ca.pem -out cert.pem
MUA用には証明書と秘密鍵から作ります
# cat private.pem cert.pem > mail.pem
作成したサーバ証明書とCA証明書が正常に作成できたか確認しておきます
# cd /etc/ssl/Server
# openssl verify -CAfile /etc/ssl/CA/cacert.pem
cert-ca.pem
cert-ca.pem: OK
# openssl verify -CAfile /etc/ssl/CA/cacert.pem
cert.pem
cert.pem: OK
Windowsなどのクライアントに証明書をインストールするための ca.der を作成します
ca証明書 をインストールしていないクライアントからWebにアクセスしようとすると下記のようなメッセージが毎回表示されます
またメールの送受信も暗号化された通信を使えません
「このサイトの閲覧を続行する」をクリックすれば、Webへのアクセスは可能になりますが
毎回聞かれないように ca証明書 をインストールしておきます

# cd /etc/ssl/CA
# openssl x509 -inform pem -in cacert.pem -out
ca.der -outform der
ここで作った ca.der を Windows のデスクトップにコピーしてインストールします
ca.der をダブルクリックして証明書のインストールを開始します

インポート先は 「認証されたルート証明機関」 にインポートします

最後に完了をクリックして、証明書のインストールは完了です

次に、SSL暗号を使ってメールを読み出すために dovecot の認証を設定します
# cd /etc/dovecot/
# vi dovecot.conf
#ssl_cert_file =
/etc/ssl/certs/ssl-cert-snakeoil.pem
#ssl_key_file =
/etc/ssl/private/ssl-cert-snakeoil.key
ssl_cert_file = /etc/ssl/Server/cert.pem ← 書き換えます
ssl_key_file = /etc/ssl/Server/mail.pem
← 書き換えます
同様に postfix の認証を設定します
# cd /etc/postfix
# vi main.cf
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_cert_file=/etc/ssl/Server/cert.pem
←
書き換えます
smtpd_tls_key_file=/etc/ssl/Server/mail.pem
←
書き換えます
6-5 SASLの設定
スパムの踏み台にならいようにするために、送信時のsmtp認証を実現させるための cyrus-sasl2 をインストールします。
# apt-get install sasl2-bin libsasl2-modules
* To enable saslauthd, edit /etc/default/saslauthd
and set START=yes
と言われたので
# vi /etc/default/saslauthd
#START=no
START=yes
に修正しておきます
smtp認証させるためには、main.cf も修正する必要があります
# vi /etc/postfix/master.cf
smtp
inet
n
-
-
-
- smtpd
#submission inet
n
-
-
-
- smtpd
# -o smtpd_enforce_tls=yes
-o
smtpd_sasl_auth_enable=yes
←
コメントアウトを外します
# -o
smtpd_client_restrictions=permit_sasl_authenticated,reject
smtps inet
n
-
-
-
-
smtpd ← コメント
アウトを外します
-o
smtpd_tls_wrappermode=yes
← コメントアウトを外します
465
番ポートでも動かせるように(OP25対策)
-o
smtpd_sasl_auth_enable=yes
←
コメントアウトを外します
# -o
smtpd_client_restrictions=permit_sasl_authenticated,reject
次に、SASLのパスワードを設定します
# saslpasswd2 -c -u boston.com matsuzaka
Password: ******
← パスワードを2回入力します。 適時変更
願います。
Again (for verification):******
データベースのアクセス権を変更します
# chmod 640 /etc/sasldb2
# cp /etc/sasldb2 /var/spool/postfix/etc/
# chgrp postfix /var/spool/postfix/etc/sasldb2
smtpd.conf に認証方法を設定します。なければ新規に作成します。
# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: auxprop
mech_list: cram-md5 digest-md5 plain login
postfix でSASLが使えるように設定を追加します
# /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
#smtpd_sasl_local_domain = $myhostname
smtpd_sasl_local_domain = boston.com
← 適時変更願います
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks,
permit_auth_destination, permit_sasl_authenticated, reject
broken_sasl_auth_clients = yes
postfix を再起動させておきます
# /etc/init.d/postfix restart
認証のテストを行います
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 fenwaypark.boston.com ESMTP Postfix (Ubuntu)
EHLO
localhost
← 入力します
250-fenwaypark.boston.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH CRAM-MD5 NTLM DIGEST-MD5 LOGIN PLAIN
250-AUTH=CRAM-MD5 NTLM DIGEST-MD5 LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth plain
bWF0c3V6YWthAG1hdHN1emFrYQBwYXNzd29yZA==
← 入力します※
235 2.0.0 Authentication successful
quit
← quitで終了させます
Authentication successful が返ってきたら設定完了です
※ perl -MMIME::Base64 -e 'print
encode_base64("username\0username\0password");'
で出来たコードです
たとえば、username=matsuzaka password=password の場合は
# perl -MMIME::Base64 -e 'print
encode_base64("matsuzaka\0matsuzaka\0password");'
bWF0c3V6YWthAG1hdHN1emFrYQBwYXNzd29yZA==
となります
6-6 postgreyの設定
SPAM対策として、従来のブラックリストを参照する方法に加えて、怪しげな接続をじらせて拒否(相手が接続を切る)方法も
使います。
これらの方法を組み合わせて、SPAMの約99%は拒否出来ているようです。
こちらのサイトを参考にさせていただきました
http://k2net.hakuba.jp/targrey/
最初に postgrey をインストールします
# apt-get install postgrey
次に、上記のサイトからパッチをダウンロードして当てます
$ wget k2net.hakuba.jp/pub/targrey-0.30-postgrey-1.27.patch
$ su
# cp targrey-0.30-postgrey-1.27.patch /usr/sbin/
# cd /usr/sbin
# patch < targrey-0.30-postgrey-1.27.patch
patching file postgrey
Hunk #10 succeeded at 537 (offset 1 line).
Hunk #11 succeeded at 556 (offset 1 line).
Hunk #12 succeeded at 628 (offset 1 line).
# cp postgrey /usr/local/sbin/postgrey
# cp /etc/postgrey/whitelist_* /etc/postfix/
postfix の main.cf に下記を追加します
# vi /etc/postfix/main.cf
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
permit_auth_destination
reject_unauth_destination
check_client_access
regexp:/etc/postfix/permit_client_nots25r ← 追加します
check_policy_service inet:60000 ← 追加します
permit
smtpd_data_restrictions =
permit_mynetworks
permit_sasl_authenticated
check_client_access
regexp:/etc/postfix/permit_client_nots25r ← 追加します
check_policy_service inet:60000 ← 追加します
permit
次にじらす接続元を正規表現で表します
Feb 10 19:56:51 fenwaypark postfix/smtpd[16402]: connect from
unknown[xxx.xxx.xxx.xxx]
など不明な接続元をひっかけます
# vi /etc/postfix/permit_client_nots25r
(参考例)
/\.dip\.t-dialin\.net$/
WARN
/\.dyn\.optonline\.net$/
WARN
/\.(adsl|cable)\.wanadoo\.nl$/
WARN
/\.(internetdsl|adsl|sdi)\.tpnet\.pl$/
WARN
/\.dyn\.user\.ono\.com$/
WARN
/\.pppoe\.mtu-net\.ru$/
WARN
/\.t-ipconnect\.de$/
WARN
!/(^unknown$)|(^[^\.]*[0-9][^0-9\.]+[0-9])|(^[^\.]*[0-9]{5})|(^([^\.]+\.)?[0-9][^\.]*\.[^\.]+\..+\.[a-z])|
(^[^\.]*[0-9]\.[^\.]*[0-9]-[0-9])|(^[^\.]*[0-9]\.[^\.]*[0-9]\.[^\.]+\..+\.)|
(^(dhcp|dialup|ppp|adsl|dsl|dynamic)[^\.]*[0-9])/ OK
/./
WARN
日本国内で明らかに問題のないサイトもこのルールにかかってしまう場合もありますので、事前に分かっている優良サイトを
ホワイトリストで救います
こちら(http://www.gabacho-net.jp/anti-spam/white-list.txt)からホワイトリストをダウンロードし
て使わせていただきます
ホワイトリストを用意していないと、amazon.com などもかかってしまいます
whitelist-list.txt
をコピーして /etc/postfix/postgrey_whitelist_clientsとして保存し、行の最後のOKを削除しておき
ます
ここで、postgrey を一旦止めて、tarpiting を有効にして再起動させます
下記は、65秒じらせて接続を切っても、1800秒(30分)以上開けて2回以上接続して来たところからのメールは受け取るという意味です
# /etc/init.d/postgrey stop
#
/usr/local/sbin/postgrey
--dbdir=/var/lib/postgrey--pidfile=/var/run/postgrey.pid --daemonize
--inet=127.0.0.1:60000 --tarpit=65 --retry-count=2 --delay=1800
毎回やるのも大変なので、起動時に出来るように設定します
ホワイトリストの指定もここで行っておきます
# vi /etc/default/postgrey
POSTGREY_OPTS="--inet=127.0.0.1:60000
--whitelist-clients=/etc/postfix/postgrey_whitelist_clients --tarpit=65
--retry-count=2 --delay=1800"
vi /etc/init.d/postgrey
#DAEMON=/usr/sbin/postgrey
DAEMON=/usr/local/sbin/postgrey
← に変更しておきます
この後、postgrey,postfix を再起動させておきます
# /etc/init.d/postgrey start
# /etc/init.d/postfix restart
ここでログに
Nov
28 03:54:54 fenwaypark postgrey[4823]: fatal: Can't call method
"txn_commit" on an undefined value at /usr/local/sbin/postgrey line
223.
Nov 28 03:54:55 fenwaypark postfix/smtpd[4942]: warning:
connect to 60000: Connection refused
Nov 28 03:54:55 fenwaypark postfix/smtpd[4942]: warning:
problem talking to server 60000: Connection refused
のようなエラーメッセージが出たら、こちらからhttps://edge.launchpad.net/~blueyed/+archive/+index?name_filter=db4.4
db4.4-util_4.4.20-8.1ubuntu3.1~blueyedppa1_i386.deb
をダウンロードして、db4 をアップデートしておきます
# dpkg -i libdb4.4_4.4.20-8.1ubuntu3.1~blueyedppa1_i386.deb
postgrey のデータベースに登録された再送待ちリストを確認してみます
# /usr/bin/db4.4_dump -p /var/lib/postgrey/postgrey.db
VERSION=3
format=print
type=btree
db_pagesize=4096
HEADER=END
98.28.3.163/hogehoge@spam.com/matsuzaka@boston.com
1205928389,1205928389,0
DATA=END
この場合、1通の再送待ちメールがあることが分かります
次に再送されてスパムではないと登録されたリストを確認してみます
VERSION=3
format=print
type=btree
db_pagesize=4096
HEADER=END
xxx.xxx.xxx.xxx
DATA=END
ひとつのアドレスが登録されているので、このアドレスは次回から待たされずに受信されます
もし、ここにSPAMが誤って登録されていたら、SPAMではないアドレスをホワイトリストに登録後、ファイルを削除して
postgrey を再起動させます
再起動後、新たなデータベースが作成されます
# ls /var/lib/postgrey/
__db.001
__db.002 __db.003 __db.004 __db.005
log.0000000001 postgrey.db postgrey.lock
postgrey_clients.db
6-7 ウイルス対策 amavisd-new, clamav の設定
メールのウイルス対策として、amavisd-new と clamav をインストールします
amavisd と spamassassin
との組み合わせでSPAMのフィルターを実現することも出来ますが、私はSPAMは「受け取ったら負け」という考えなので
SPAMを受け取った後の対応はしません
# apt-get install amavisd-new clamav clamav-daemon
amavisd を設定するまえに、ホストネームを確認しておいきます
# hostname --fqdn
fenwaypark.boston.com
amavisd を設定します
vi /etc/amavis/conf.d/05-node_id
# To manually set $myhostname, edit the following line with
the correct Fully
# Qualified Domain Name (FQDN) and remove the # at the
beginning of the line.
#
#$myhostname = "mail.example.com";
$myhostname = "fenwaypark.boston.com";
← hostname --fqdn
を実行して確認したホストネームです
amavisd を起動させておきます
# /etc/init.d/amavis start
amavisd が10024ポートを見ているかを確認しておきます
# netstat -an | grep 10024
tcp
0 0
127.0.0.1:10024
0.0.0.0:*
LISTEN ←
Listen していればよいです
起動しているか確認してみます
# ps aux | grep amavis
amavis
21268 0.0 2.3 30416 23476
? Ss
21:49 0:00 amavisd (master)
amavis
21269 0.0 2.2 31184 22892
? S
21:49 0:00 amavisd (virgin child)
amavis
21270 0.0 2.3 31316 23788
? S
21:49 0:00 amavisd (ch1-avail)
念のため、telnet で 10024ポートにアクセスしてみます
# telnet localhost 10024
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 [127.0.0.1] ESMTP amavisd-new service ready
← amavisd のサービスが ready になっていればよいです
quit
← quit で終了します
221 2.0.0 [127.0.0.1] amavisd-new closing transmission channel
Connection closed by foreign host.
README.postfix を読んでみると
2. With a text editor add to the Postfix master.cf file
the following two entries, e.g. near the end of the file:
smtp-amavis
unix -
- y/n
- 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
127.0.0.1:10025
inet n -
y/n -
- smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_delay_reject=no
-o
smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o
smtpd_recipient_restrictions=permit_mynetworks,reject
-o
smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o
receive_override_options=no_header_body_checks,no_unknown_recipient_checks
Change the 'y/n' to either 'y' or 'n', depending on how you prefer
the smtp and smtpd postfix services to run - either
chroot-ed, or not.
See your other (normal) smtp and smtpd postfix services in
master.cf
and use the same setting here.
5. Tell Postfix to start forwarding all mail it receives to
amavisd-new
for content inspection.
To the Postfix main.cf file add a line:
content_filter=smtp-amavis:[127.0.0.1]:10024
either with a text editor, or preferably using a shell command:
# postconf -e 'content_filter=smtp-amavis:[127.0.0.1]:10024'
と書いてあるので、main.cf と master.cf を修正しておきます
# vi /etc/postfix/main.cf
適当なところに、追加しておきます
content_filter=smtp-amavis:[127.0.0.1]:10024
master.cf は
# vi /etc/postfix/master.cf
上記のサンプルの y/n を n として、最後のところに追加しておきます
smtp-amavis
unix -
- n
- 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
127.0.0.1:10025
inet n -
n - -
smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_delay_reject=no
-o
smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o
smtpd_recipient_restrictions=permit_mynetworks,reject
-o
smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o
receive_override_options=no_address_mappings,no_header_body_checks,no_unknown_recipient_checks
メールのログに、メールが届いたときに
Feb
11 13:51:19 fenwaypark amavis[13567]: (13567-10) Passed CLEAN,
[xxx.xx.xxx.xxx] <matsui@newyork.com> ->
<matsuzaka@boston.com>
となっていたら、問題なくウイルスのチャックをしています
ウイルスのパターンデータがちゃんと更新されているかチェックしておきます
# cat /var/log/clamav/freshclam.log
--------------------------------------
Received signal: wake up
ClamAV update process started at Mon Dec 17 16:58:14 2007
main.inc is up to date (version: 45, sigs: 169676, f-level:
21, builder: sven)
daily.inc is up to date (version: 5152, sigs: 8613, f-level:
21, builder: ccordes)
--------------------------------------
1時間に1回更新されているようです
なぜかメールを転送する場合、メールが2通届くので master.cf を下記のように修正しました
-o receive_override_options=no_address_mappings,no_header_body_checks,
no_unknown_recipient_checks ← 追加しました
ウイルスが正しく検出できるかをテストしてみます
まず、ここから無害のウイルスをダウンロードします
http://www.eicar.org/anti_virus_test_file.htm
eicar.comというウイルスをダ
ウンロードして、メールに添付して送信してみると、ログに
Feb
11 22:44:15 fenwaypark amavis[21269]: (21269-03) Blocked BANNED
(multipart/mixed | text/plain,.asc,eicar.com), LOCAL [192.168.0.4]
[192.168.0.4] <matsuzaka@boston.com> ->
<matsui@newyork.com>, quarantine: banned-sW2Eni59ecsG,
Message-ID: <1203169454.6339.0.camel@fenwaypark>, mail_id:
sW2Eni59ecsG, Hits: -, 376 ms
というメッセージが残り、送信者に以下の様なメールが自動送信されます
もちろんメールは配信されません
BANNED CONTENTS ALERT
Our content checker found
banned name: multipart/mixed |
text/plain,.asc,eicar.com
これで正しくウイルスチェックされていることが分かりました
モジュールのアップデート
# cat /var/log/clamav/freshclam.log
--------------------------------------
Received signal: wake up
ClamAV update process started at Sun Feb 17 16:39:20 2008
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.91.2 Recommended version: 0.92.1
DON'T PANIC! Read http://www.clamav.net/support/faq
main.inc is up to date (version: 45, sigs: 169676, f-level:
21, builder: sven)
daily.inc is up to date (version: 5845, sigs: 44251, f-level:
21, builder: ccordes)
--------------------------------------
ログにこの様な WARNING がでたら、モジュールをアップデートする必要があります
http://packages.ubuntu.com/hardy/base/
から、以下のモジュールをダウンロードして
# dpkg -l libc6_2.7-5ubuntu2_i386.deb
# dpkg -i libclamav3_0.92.1~dfsg-1_i386.deb
# dpkg -i clamav_0.92.1~dfsg-1_i386.deb
# dpkg -i clamav-base_0.92.1~dfsg-1_all.deb
# dpkg -i clamav-daemon_0.92.1~dfsg-1_i386.deb
# dpkg -i clamav-freshclam_0.92.1~dfsg-1_i386.deb
の順にインストールしていきます
7. Webサーバの設定
Webサーバは apache を使用しますが、最初からインストールされるためここではSSL暗号化について設定します
ssl用のモジュールをイネーブルにします
# a2enmod ssl
再起動させておきます
# /etc/init.d/apache2 force-reload
ports.conf に Listen 443 を追加しますが、ubuntu-server の場合は最初から入っているようです
# echo "Listen 443" >>
/etc/apache2/ports.conf
SSLで接続したときのために、port443の設定をしておきます
# vi /etc/apache2/sites-available/ssl
NameVirtualHost
*:443
← 変更します
<VirtualHost *:443>
←
変更します
ServerAdmin webmaster@localhost
SSLEngine On 追加する
SSLCertificateFile
/etc/ssl/Server/cert.pem ← 追
加します
SSLCertificateKeyFile /etc/ssl/Server/private.pem ← 追加する
DocumentRoot /var/www/
設定をイネーブルにします
# a2ensite ssl
# /etc/init.d/apache2 reload
ちなみに設定をディセーブルする場合は
# a2dissite ssl
とします
バーチャルドメインは外部のネットワークからしかアクセス出来ないので、チェック用にクライアントLinuxPCのhosts
にサーバのアドレスを追加して動作をチェックします
# vi /etc/hosts (サーバではなくクライアントの
LinuxPCで)
192.168.0.2 www.boston.com
← 適時変更ねがいます
192.168.0.2 www.seattle.com ← 適時変更ねがいます
192.168.0.2 www.newpork.com
← 適時変更ねがいます
LinuxPC でなくて Windows なPCでチェックする場合は、同様の設定を lmhosts で行います
WebのバーチャルドメインのSSL暗号化は、ひとつのドメインで両方をサポートするのは無理らしいので、それぞれのドメインに
分けてSSL暗号化を行います
例) www.seattle.com SSL暗号化しない
www.newyork.com SSL暗号化しない
www.boston.com SSL暗号化する
SSL暗号化していない、www.seattle.com や www.newyork.com で暗号化が必要な場合は、SSL暗号化している
www.boston.com に
リダイレクトするようにします
sites-available の例)
SSL暗号化していない、www.seattle.com や www.newyork.com の場合
/etc/apache2/sites-available/seattle (newyorkも同様)
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin
webmaster@seattle.com
ServerName
www.seattle.com
DocumentRoot
/var/www/seattle/public_html/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory
/var/www/seattle/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
RedirectMatch ^/IlohaMail https://www.boston.com
← SSL化が必要な場合はリダイレクト
させます
</Directory>
ScriptAlias /cgi-bin/
/usr/lib/cgi-bin/
<Directory
"/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog
/var/log/apache2/seattle/error.log
# Possible values include:
debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog
/var/log/apache2/seattle/access.log combined
# ServerSignature On
ServerSignature Off
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes
MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from
127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
SSL暗号化する、www.boston.com の場合
/etc/apache2/sites-available/boston
<VirtualHost *:80> と <VirtualHost *:443> を両方用意します
NameVirtualHost *:443
<VirtualHost *:80>
ServerAdmin
webmaster@boston.com
ServerName www.boston.com
Redirect permanent /
https://www.boston.com/
DocumentRoot
/var/www/boston/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory
/var/www/boston/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
</Directory>
ScriptAlias /cgi-bin/
/usr/lib/cgi-bin/
<Directory
"/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog
/var/log/apache2/boston/error.log
# Possible values include:
debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog
/var/log/apache2/boston/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes
MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from
127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin
webmaster@boston.com
SSLEngine On
SSLCertificateFile /etc/ssl/Server/cert.pem
← SSL証明書の保
存場所です
SSLCertificateKeyFile
/etc/ssl/Server/private.pem ← SSL証明書の保存場所で
す
ServerName www.boston.com
DocumentRoot
/var/www/boston/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory
/var/www/boston/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /IlohaMail/
</Directory>
<DirectoryMatch
/usr/share/IlohaMail/source/>
Options +FollowSymLinks
AllowOverride None
order allow,deny
allow from all
</DirectoryMatch>
ScriptAlias /cgi-bin/
/usr/lib/cgi-bin/
<Directory
"/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog
/var/log/apache2/boston/error.log
# Possible values include:
debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog
/var/log/apache2/boston/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes
MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from
127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
7. FTPサーバの設定
FTPサーバの設定をします。
まず、proftpd をインストールします
# apt-get install proftpd
FTPサーバは standalone で動作させます
Adding new user `proftpd' (UID 113) with group `nogroup' ...
Not creating home directory `/var/run/proftpd'.
* Starting ftp server
proftpd
- IPv6 getaddrinfo 'fenwaypark.boston.com' error: Name or service
not known
とIPv6のエラーが出ましたので、proftpd.conf で UseIPv6 を off にしておきます
# vi /etc/proftpd/proftpd.conf
# Set off to disable IPv6 support which is annoying on IPv4
only boxes.
#UseIPv6
on
UseIPv6
off ← off にしておきます
ドキュメントルートの設定をしておきます
homeディレクトリ以上に行けないようにします
# Use this to jail all users in their homes
#
DefaultRoot
~
DefaultRoot
← コメントアウトを外します
タイムアウトのエラーが出るとユーザの方から聞いたので、タイムアウトの設定を大きめに変更しました
単位はそれぞれ秒です
TimeoutLogin 300
TimeoutNoTransfer 3600
TimeoutStalled 3600
TimeoutIdle 3600
proftpd を再起動させておきます
# /etc/init.d/proftpd restart