install†
open-ssl†
wget http://www.openssl.org/source/openssl-0.9.8a.tar.gz
tar xvfz ./openssl-0.9.8a.tar.gz
cd openssl-0.9.8a
./config -fPIC shared
make
make install
config†
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
/sbin/ldconfig
apache本体†
http://www.apache.org/dist/httpd/
wget http://www.apache.org/dist/httpd/httpd-2.0.59.tar.gz
tar xzfp httpd-2.0.5*tar.gz
cd httpd-2.0.5?
./configure --enable-shared=yes --enable-dav=yes \
--enable-so --enable-ssl --enable-modules="so ssl" --with-ssl=/usr/local/ssl
make
make install
ssl key 生成†
mkdir /usr/local/apache2/conf/ssl.key
cd /usr/local/apache2/conf/ssl.key
openssl genrsa -des3 -out server.key 1024
mkdir /usr/local/apache2/conf/ssl.crt
cd /usr/local/apache2/conf/ssl.crt
openssl req -new -x509 -days 365 -key ../ssl.key/server.key -out server.crt
cd /usr/local/apache2/conf/ssl.key
openssl rsa -in server.key -out server.key
startup†
emacs /etc/rc.d/init.d/httpd
httpd
chmod +x /etc/rc.d/init.d/httpd
chkconfig --add httpd
/etc/rc.d/init.d/httpd start
シンボリックリンク†
ln -s /usr/local/apache2 /etc/httpd
ln -s /usr/local/apache2/log /var/log/httpd
httpd.conf†
CustomLog logs/access_log combined
そのディレクトリ以下に cgi と html を共存させる設定†
まず cgi-bin のディレクティブを全削除
<Directory "/var/www/html/">
AllowOverride None
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex index.cgi index.html
Order allow,deny
Allow from all
</Directory>
パスワードをかける設定†
htpasswd -c /var/www/html/.htpasswd
<Directory "/var/www/html/">
AuthName 【username】
AuthType Basic
AuthUserFile /var/www/html/.htpasswd
Require valid-user
</Directory>
バーチャルホスト†
NameVirtualHost *
<VirtualHost *>
Servername hogehoge
</VirtualHost>
<VirtualHost *>
</VirtualHost>
バーチャルホストのステータス取得
apache 1.3系 httpd -S
apache 2.0系 httpd- t -D DUMP_VHOSTS
ファンシーINDEX†
Options Indexes
※ 日本語ファイルが文字化けする場合はそのディレクトリごとに AddDefaultCharset UTF-8 等を加えておく
プログラム系†
きっちり書こうcontent-type†
METAタグよりhttp-header の content-type が優先される
print 'Content-type: text/html; charset=euc-jp\n\n';
print 'Content-type: text/html; charset=Shift-JIS\n\n';
IP 制限†
<Location />
Order deny,allow
Deny from all
Allow from 192.168.0.0/24
</Location>
ius†
yum install https://repo.ius.io/ius-release-el7.rpm
yum remove httpd mod_ssl httpd-tools
yum –disablerepo=base,extras,updates –enablerepo=ius,epel install httpd mod_ssl
ssl.conf を rpmsave から復元して httpd 再起動
windows 版†
download してくる
C: 直下に置く Apache24 を置く
cd /cygdrive/c/Apache24/conf
servername の # を消す
cd /cygdrive/c/Apache24/bin
./httpd
常に起動する場合は
./httpd -k install
セキュリティ設定†
httpd.conf
Options FollowSymLinks
TraceEnable off
ServerSignature Off
ServerTokens Prod
Header unset X-Powered-By
Options -Indexes
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options nosniff
Header append X-FRAME-OPTIONS "SAMEORIGIN"
※ ubuntu の場合は下記で header を有効化
sudo a2enmod headers
ssl.conf
SSLCompression off
SSLHonorCipherOrder on
# ↓動かなくなるものもあるのでその場合は外す
Header edit Set-Cookie ^(.*)$ $1;secure;HttpOnly
SSLProtocol -ALL +TLSv1.2
SSLCipherSuite !DSS:EDH+AESGCM:ECDSA+AESGCM:EECDH+AESGCM:-AES128
# ちょっと強すぎて動かないものもあるのでその場合は↓
# SSLCipherSuite !3DES:!aNULL:EDH+HIGH:ECDH+HIGH:-AES128:-3DES:-DSS:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA
welcome page と icons を削除
\cp /dev/null /etc/httpd/conf.d/autoindex.conf
\cp /dev/null /etc/httpd/conf.d/welcome.conf
SSL†
https://www.ssllabs.com/ssltest/
owasp zap†
html lint†
http://www.htmllint.net/html-lint/htmllint.html
特定IPだけ許可その他はパスワ†
sudo htdigest -c /etc/httpd/conf/.htdigest "Digest Auth" test
AuthType Digest
AuthName "Digest Auth"
AuthUserFile /etc/httpd/conf/.htdigest
<RequireAny>
Require ip 192.168.0.100/24 10.0.0.1/32
Require valid-user
</RequireAny>