「Apache」カテゴリーアーカイブ

FedoraのApacheにテスト用のSSL(自己署名証明書)を設定

Chromeに対応するためには、subjectAltNameを設定した自己署名証明書を作成する必要があります。
subjectAltNameが設定されていない証明書はChromeで NET::ERR_CERT_COMMON_NAME_INVALID エラーを参照してください。

あらかじめ用意されているテスト用の仮の鍵と証明書をバックアップする。

# cd /etc/pki/tls
# mv private/localhost.key private/localhost.key.bk
# mv certs/localhost.crt certs/localhost.crt.bk

サーバ鍵を作成する。

# openssl genrsa -out private/test.key 2048

これでパスフレーズなしのサーバ鍵が作成される。

テスト用に自己証明書を作成。

# openssl req -new -x509 -days 3650 -sha256 -key /etc/pki/tls/private/test.key -out /etc/pki/tls/certs/test.crt
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) [GB]:JP
State or Province Name (full name) [Berkshire]:Tokyo
Locality Name (eg, city) [Newbury]:Chiyoda-ku
Organization Name (eg, company) [My Company Ltd]:Pistolfly Co., Ltd.
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:test.pistolfly.jp
Email Address []:webmaster@pistolfly.jp
# apachectl restart

あとは、/etc/httpd/conf.d/ssl.confにバーチャルホストを設定して、
・サーバ鍵と証明書のパス
・その他バーチャルホストの設定
を行う。

MacPortsのApache2にテスト用のSSL(自己署名証明書)を設定

Chromeに対応するためには、subjectAltNameを設定した自己署名証明書を作成する必要があります。
subjectAltNameが設定されていない証明書はChromeで NET::ERR_CERT_COMMON_NAME_INVALID エラーを参照してください。

SSLのテスト用に、MacPortsでインストールしたApacheにSSLの設定をした。
conf/httpd.conf

# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf

秘密鍵と証明書ファイルのパスの設定を確認。(デフォルトのまま使用することにする。)
conf/extra/httpd-ssl.conf

#   Server Certificate:
#   Point SSLCertificateFile at a PEM encoded certificate.  If
#   the certificate is encrypted, then you will be prompted for a
#   pass phrase.  Note that a kill -HUP will prompt again.  Keep
#   in mind that if you have both an RSA and a DSA certificate you
#   can configure both in parallel (to also allow the use of DSA
#   ciphers, etc.)
SSLCertificateFile "/opt/local/apache2/conf/server.crt"
#SSLCertificateFile "/opt/local/apache2/conf/server-dsa.crt"
#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile "/opt/local/apache2/conf/server.key"
#SSLCertificateKeyFile "/opt/local/apache2/conf/server-dsa.key"

秘密鍵の作成。

$ cd /opt/local/apache2/conf/
$ sudo openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.......................+++
..+++
e is 65537 (0x10001)

自己証明書を作成。

$ sudo openssl req -new -x509 -days 3650 -sha256 -key server.key -out server.crt
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]:Tokyo
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:*.example.com
Email Address []:

Leopardにmacportsでapache2をインストール

$ sudo port install apache2
Password:
--->  Fetching pcre
--->  Attempting to fetch pcre-7.7.tar.bz2 from ftp://ftp.fu-berlin.de/unix/misc/pcre/
--->  Verifying checksum(s) for pcre
--->  Extracting pcre
--->  Configuring pcre
--->  Building pcre with target all
--->  Staging pcre into destroot
--->  Installing pcre 7.7_0
--->  Activating pcre 7.7_0
--->  Cleaning pcre
--->  Fetching apache2
--->  Attempting to fetch httpd-2.2.9.tar.bz2 from http://www.apache.org/dist/httpd
--->  Verifying checksum(s) for apache2
--->  Extracting apache2
--->  Configuring apache2
--->  Building apache2 with target all
--->  Staging apache2 into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting apache2 with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
###########################################################
Warning: apache2 requests to install files outside the common directory structure!
--->  Installing apache2 2.2.9_1+darwin_9
--->  Activating apache2 2.2.9_1+darwin_9
--->  Cleaning apache2

メッセージにある通り、自動起動を設定。

$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

httpd.confを添付されているサンプルからコピーする。

$ sudo cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf

apachectlなどへのパスを通すため、.bash_profileなどで$PATHに
/opt/local/apache2/bin
を追加しておく。

mod_rewriteでForbidden You don't have permission to access

/hoge/a.htmlにアクセスしたら/hoge/b.htmlにリダイレクトするようにしようと、/hoge/.htaccessに以下のように設定した。

RewriteEngine on
RewriteRule ^a.php$ /hoge/b.php [R=301,L]

すると、、、
a.htmlにアクセスすると、

Forbidden

You don't have permission to access /hoge/a.html
on this server.

b.htmlにアクセスしても、

Forbidden

You don't have permission to access /hoge/b.html
on this server.

というエラーになる。
Apacheのerrorlogを見てみると、

Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /xxxx/xxxx/xxxx/hoge/a.html

と出ていた。
そこで、/xxxx/xxxx/xxxx/hogeのDirectoryディレクティブに、

<Directory "/xxxx/xxxx/xxxx/hoge">
  Options FollowSymLinks
</Directory>

のように設定したら、解決。
mod_rewriteには、FollowSymLinksが必要。