(事前準備の部分は省略して…実際の構築部分から)
本投稿は、Apache、バーチャルホストの設定、SiteGardLite、SSH、Firewallの設定です。
Nginxを使ってみたいのですが、SiteGardLiteとの連携の点でちょっと難しそうなのでPVもそんなにないしそのままApacheで使用することにしました。
- さくらのVPSのコンパネにログインして、OSインストール→標準OSインストール→「SiteGardLite CentOS7(x84_x64)」を選択して再インストールしちゃいます。
- インストール後SSHでログインして、アップデートして初期設定。
- アップデート、ロケールの設定、メールエイリアスの設定、ユーザの追加、SSHの設定、FWの設定
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455# アップデートyum update -y# ロケールの設定localectl set-locale LANG=ja_JP.UTF-8# メールエイリアスの設定cat /etc/aliases ENDroot: xxxx@xxxx.xxxENDnewaliases# ユーザの追加useradd hogehogepasswd hogehoge(password phrase)usermod -G wheel hogehoge# SSHの設定su - hogehogemkdir ~/.sshcat> ~/.ssh/authorized_keys << ENDssh-rsa (鍵情報…)ENDchmod 600 ~/.ssh/authorized_keyschmod 700 ~/.ssh/exitvi /etc/ssh/sshd_config#Port 22Port 20022#PermitRootLogin yesPermitRootLogin no#PasswordAuthentication yesPasswordAuthentication no#UsePAM yesUsePAM no# SSHDの再起動とFirewallの起動・有効化systemctl reload sshdsystemctl start firewalldsystemctl enable firewalld# FirewallへのSSHポートの追加firewall-cmd --permanent --zone public --add-port 20022/tcpsystemctl restart firewalld# 接続の確認後 22番ポートを止める、SoftEther用のPortを開けておく# L2TP 500,4500 Softether xxxx SiteGardLite 9443firewall-cmd --list-allfirewall-cmd --permanent --zone=public --remove-service=sshfirewall-cmd --permanent --add-service=httpsfirewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --zone public --add-port 500/udpfirewall-cmd --permanent --zone public --add-port 4500/udpfirewall-cmd --permanent --zone public --add-port xxxx/tcpfirewall-cmd --permanent --zone public --add-port 9443/tcpsystemctl restart firewalld - SiteGardLiteのインストール
ンターネット側からアクセスできるようにしてあるが、後にVPN経由でないとアクセスできないように変更する。
詳細な手順書はさくらVPSのヘルプ参照。あえてアーカイブのファイル名はマスクしているので手順書参照。
1234567cd /opt/jp-secure/siteguardlite/./setup.shcd## 3.0から3.2へのアップデートwget http://progeny.sakura.ad.jp/siteguard/xxxx/apache/siteguardlitexxxxxxx.rpmrpm -Uvh siteguardlite-xxxxx.rpm#### admin/admin で https://hostname:9443 にアクセスしてID/PWを変更する - Logwatchのインストール
1234yum install -y logwatchvi /usr/share/logwatch/default.conf/logwatch.confMailTo = Logwatch@xxxxx.xxxxDetail = High - Apache2.4の設定(/etc/httpd/conf/httpd.conf)
123456789101112131415161718192021rm -rf /etc/httpd/conf.d/welcome.confvi /etc/httpd/conf/httpd.conf=========================DocumentRoot "/var/www/html"Options Includes ExecCGI FollowSymLinks#AllowOverride NoneAllowOverride All<IfModule dir_module>DirectoryIndex index.html index.php</IfModule>#コメントアウト#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"AddHandler cgi-script .cgi .pl#コメントアウト#AddDefaultCharset UTF-8## 追加TraceEnable off - Apache2.4の設定(/etc/httpd/conf.d/autoindex.conf)
123456<Directory "/usr/share/httpd/icons">#iconsディレクトリのファイル一覧を表示しないようにするOptions MultiViewsAllowOverride NoneRequire all granted</Directory> - ln -s /usr/bin/perl /usr/local/bin/perl
- バーチャルホストの設定
フォルダの作成
mkdir -p /var/www/vhost/hogehoge.xxx
1234567891011121314151617181920212223cat >> /etc/httpd/conf.d/vhost.conf <<END## unknown host names -> deny<VirtualHost _default_:80>ServerName any<Location />Require all denied</Location></VirtualHost>## hogehoge.xxx は適宜変更<VirtualHost *:80>ServerName hogehoge.xxxServeralias www.hogehoge.xxxDocumentRoot /var/www/vhost/hogehoge.xxxErrorLog logs/hogehoge.xxx-error_logSetEnvIf Remote_Addr xxx.xxx.xxx.xxx no_logCustomLog logs/hogehoge.xxx-access_log<Directory /var/www/vhost/hogehoge.xxx>AllowOverride All</Directory></VirtualHost>END - SSLの設定
vi /etc/httpd/conf.d/ssl.conf
SSLProtocol all -SSLv2 -SSLv3 - Apacheの再起動・デーモンの有効化
systemctl restart httpd
systemctl enable httpd - PHPアクセラレータ「OPcache」、KVSの「APCu」を導入する
123456789101112131415161718192021222324## 参照URL## http://www.atmarkit.co.jp/ait/articles/1602/25/news017.htmlpecl install zendopcache-7.0.5pecl install apcu-4.0.10vi /etc/php.d/apc.ini[opcache]zend_extension = /usr/lib64/php/modules/opcache.soopcache.enable = 1opcache.enable_cli = 1opcache.memory_consumption = 128opcache.interned_strings_buffer = 8opcache.max_accelerated_files = 4000opcache.blacklist_filename = /etc/php.d/opcache*.blacklist[apcu]extension = apcu.soapc.enabled = 1apc.enable_cli = 1apc.shm_size = 64Mapc.mmap_file_mask = /tmp/apc.XXXXXXsystemctl restart httpd - Let’s Encryptを導入する
yum install -y certbot certbot-apache
certbot run –apache -d hogehoge.xxx
#メールアドレスの入力、同意確認、SSHをどうしようするか確認される
#1だと新たにSSL用のVhost.confを作成してくれるだけ、2だとHTTP->HTTPSへのリダイレクトなはず。。。 - Apacheの再起動
これで問題なくアクセスできるか確認する。 - Let’s Encryptの自動更新コマンドをCronに書いておく(※記述が間違っていたので修正 17/7/17)
123crontab -e#### Let's Encrypt05 1 * * 1 certbot renew --pre-hook "service stop httpd" --post-hook "service start httpd" >> /var/log/letsencrypt.log
実行時間とかは、環境に合わせて修正してくださいな。