質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
mod_rewrite

ApacheウェブサーバーのためのURL書き換えモジュールです。主にプリティーURLに使われていますが、同様に単純置換を超えた、多様なタスクの処理能力や柔軟性があります。

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

SSL

SSL(Secure Sockets Layer)とは、暗号化されたプロトコルで、インターネット上での通信セキュリティを提供しています。

Q&A

解決済

2回答

1949閲覧

SSLバーチャルホストへリダイレクトされない理由を教えてください

stargryps

総合スコア8

mod_rewrite

ApacheウェブサーバーのためのURL書き換えモジュールです。主にプリティーURLに使われていますが、同様に単純置換を超えた、多様なタスクの処理能力や柔軟性があります。

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

SSL

SSL(Secure Sockets Layer)とは、暗号化されたプロトコルで、インターネット上での通信セキュリティを提供しています。

0グッド

0クリップ

投稿2018/10/15 03:06

編集2018/10/15 04:32

前提・実現したいこと

前提
※環境を以下に列挙します。

設定しているサーバー:ホスト名を仮にwwwとします。(既存の動作しているwwwからのリニューアルです。)
環境:CentOS7.4、Apache 2.4.34、mod_ssl 2.4.34(いずれもIUSリポジトリから)、OpenSSL 1.0.2k-12(CentOS7.4固有の)
SSLは有償のものを使用。バーチャルホストとして、wwwとhomeの2つを設定しています。
このwwwサーバーにはコンテンツは何も置いておらず、ProxyPassを設定してリダイレクトさせたいサーバーへアクセスを流しているだけのサーバーになります。

リダイレクトさせたいサーバー:ホスト名を仮にprod1とします。
環境:RedHat Enterprise Linux 4.5、Apache、mod_ssl等

実現したいこと:以下の事をwwwサーバーでさせたいと思っています。
1.http://www.test.com -> https://www.test.comにリダイレクト
2.http://www.home.com/intranet -> https://home.com/intranetにリダイレクト(実際のintranetコンテンツはprod1にあります。)

ここに質問の内容を詳しく書いてください。
httpd.conf、ssl.confを設定してApacheは起動しているのですが、以下の事象が発生しました。1

発生している問題・エラーメッセージ

1.http://www.test.comにはアクセスできるが、https://www.test.comにリダイレクトされない
(そもそも、リダイレクトエラーがerror_logに出力されていない)
2.直接https://www.test.comにアクセスすると、画面は表示されない
3.Apacheのエラーメッセージにはよくわからない通知?表示が出ている。

/var/log/error_log
(Apache起動時にメッセージが表示され、サイトにアクセスした際には何もエラーメッセージは書かれません。)

[Mon Oct 15 10:38:30.338799 2018] [suexec:notice] [pid 4360] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Mon Oct 15 10:38:30.358289 2018] [mpm_prefork:notice] [pid 4360] AH00163: Apache/2.4.34 (IUS) OpenSSL/1.0.2k-fips configured -- resuming normal operations [Mon Oct 15 10:38:30.358314 2018] [core:notice] [pid 4360] AH00094: Command line: '/usr/sbin/httpd -D SSL -D FOREGROUND'

該当のソースコード

/etc/httpd/conf/httpd.conf抜粋

##Apache listen port Listen 80 ##choice of modules.d/conf Include conf.modules.d/00-base.conf Include conf.modules.d/00-mpm.conf Include conf.modules.d/00-proxy.conf Include conf.modules.d/00-systemd.conf ##FQDN and port ServerName www.test.com:80 ServerName www.test.com:443 ##symboliklink yes .htaccess none <Directory /> Options FollowSymLinks #AllowOverride all AllowOverride None #Require all granted </Directory> <Directory "/var/www"> AllowOverride None # Allow open access: # Require all granted Require all denied </Directory> <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None # Require all granted Require all denied </Directory> #<IfModule dir_module> # DirectoryIndex index.html #</IfModule> <Files ".ht*"> Require all denied </Files> ErrorLog "logs/error_log" LogLevel warn <IfModule log_config_module> LogFormat "domain:%V\thost:%h\tserver:%A\tident:%l\tuser:%u\ttime:%{%d/%b/%Y:%H:%M:%S %z}t\tmethod:%m\tpath:%U%q\tprotocol:%H\tstatus:%>s\tsize:%b\treferer:%{Referer}i\tagent:%{User-Agent}i\tresponse_time:%D\tcookie:%{cookie}i\tset_cookie:%{Set-Cookie}o" combined_ltsv </ifModule> CustomLog "logs/access_log_ltsv" combined_ltsv <Directory "/var/www/cgi-bin"> AllowOverride None Options None # Require all granted Require all denied </Directory> EnableSendfile off IncludeOptional conf.d/*.conf TraceEnable off HostnameLookups Off UseCanonicalName Off

該当のソースコード

/etc/httpd/conf.d/rewrite.conf

<IfModule rewrite_module> RewriteEngine On Loglevel alert rewrite:trace8 RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] </IfModule>

該当のソースコード

/etc/httpd/conf.d/ssl.conf

#listen port Listen 443 <VirtualHost 192.168.2.1:80> #http://www.test.com/ ServerName www.test.com ServerAdmin webmaster@test.com ErrorLog logs/www_error_log LogLevel warn ProxyPass / http://prod1.com/ ProxyPassReverse / http://prod1.com/ </VirtualHost> <VirtualHost 192.168.2.1:443> #https://www.test.com/ ServerName www.test.com ServerAdmin webmaster@test.com ErrorLog logs/www_error_log LogLevel warn ProxyPass / http://prod1.com/ ProxyPassReverse / http://prod1.com/ </VirtualHost> <VirtualHost 192.168.2.2:443> #https://home.test.com/ ServerName home.test.com ServerAdmin webmaster@test.com SSLProxyEngine on ErrorLog logs/home-ssl_error_log CustomLog logs/home-ssl_access_log combined_ltsv LogLevel warn BrowserMatch "MSIE [2-5]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0 CustomLog logs/home-ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" Options All Options -Indexes ProxyPass / https://prod1.com/ ProxyPassReverse / https://prod1.com/ </VirtualHost>

試したこと

1.リダイレクトの設定箇所が問題か
htt.conf内に記載していたrewrite.confの内容をrewrite.confとして外出し->効果なし
2.SSL付きでApacheが起動していない?
/etc/sysconfig/httpd内のOPTIONS=に"DSSL"を付けて起動->効果なし
3.IfModule rewrite_moduleをIfModule mod_rewrite_soに変更->効果なし

他にもいろいろやったのですが、メモしていませんでいた。すいません。

補足情報(FW/ツールのバージョンなど)

なし。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

単なるタイプミスならすみませんが、

RewriteRule ^(.*)$ https://%{HTTP_POST}%{REQUEST_URI} [R,L]

HTTP_POST -> HTTP_HOST

リダイレクトされない理由がこれだった場合、その他の質問を書き直した方がよいかと思います。

投稿2018/10/15 03:15

ssasaki

総合スコア1167

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ssasaki

2018/10/15 04:51

単なるタイプミスだったようですが、であれば、、、 1.http://www.test.comにはアクセスできるがhttps://www.test.comにリダイレクトされない (そもそも、リダイレクトエラーがerror_logに出力されていない) これは具体的にどのような現象となっているのでしょうか? エラーページが出る、空白ページが出る、タイムアウトする等々あると思いますが。 また、上記の時のアクセスログ、エラーログはどうなっていますか?
stargryps

2018/10/15 06:26

ssasakiさん IEでもChromeでもhttp://www.test.comが表示されたままで、リダイレクトすらされません。 更に、https://www.test.comにアクセスすると、「Internet Explorerではこのページは表示できません」となり、Chromeでは「このサイトは安全に接続できません www.test.comから無効な応答が送信されました」、「ERR_SSL_PROTOCOL_ERROR」となっています。 httpサイトに接続できた際のアクセスログは下記の通りです。 access_log_ltsvには domain:www.test.com host:219.106.254.33 server:192.168.2.1 ident:- user:- time:15/Oct/2018:15:02:28 +0900 method:GET path:/ protocol:HTTP/1.1 status:200 size:54091 referer:- agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 response_time:3951 cookie:- set_cookie:- www-ssl_access_log domain:www.test.com host:xxx.xxx.xxx.xxx(wwwのグローバルIP) server:192.168.2.1 ident:- user:- time:15/Oct/2018:15:02:35 +0900 method:- path:- protocol:HTTP/1.0 status:400 size:226 referer:- agent:- response_time:147 cookie:- set_cookie:- www-ssl_request_log [15/Oct/2018:15:02:35 +0900] xxx.xxx.xxx.xxx(wwwのグローバルIP) - - "\x16\x03\x01\x02" 226 httpsサイトにつながらなかった場合には、エラーログにも何も表示されません。
ssasaki

2018/10/15 06:55

httpが表示されたまま、、、というのは、要するにリダイレクトがなければ表示されるべきものが表示されているということですね? 記載されている情報を見て気になるのは、 Include conf.modules.d/00-base.conf のように、これらを明記して読み込んでいることですね。 rewrite.conf や ssl.conf は確実に読み込まれているのでしょうか? 一度、httpd.conf 内の Include 文をすべて確認してみては? また、root ユーザーで以下のコマンドを実行すると何が返ってきますか? ss -nap |grep 443
stargryps

2018/10/15 07:50

ssasakiさん mod_rewriteは/conf.modules.d/00-base.conf内にあり、コメントアウトもしていないため、読み込んでおります。 モジュールconfをあえて選別して書いている理由としては、00-dav.confや00-lua.confについては読み込ませたくないため、あえてこのようにしています。 また、ssl.confについては/conf.d/ssl.confにありますが、こちらはhttpd.confの中に IncludeOptional conf.d/*.conf として読み込むようにしています。 なお、ss -nap|grep 443の結果ですが、以下のようになりました。 [root@www ~]# ss -nap|grep 443 u_str ESTAB 0 0 /run/systemd/journal/stdout 28443 * 29175 users:(("systemd-journal",pid=523,fd=86),("systemd",pid=1,fd=123)) u_str ESTAB 0 0 * 29175 * 28443 users:(("gvfs-afc-volume",pid=1988,fd=1)) tcp LISTEN 0 128 :::443 :::* users:(("httpd",pid=5220,fd=6),("httpd",pid=5219,fd=6),("httpd",pid=5218,fd=6),("httpd",pid=5217,fd=6),("httpd",pid=5216,fd=6),("httpd",pid=5215,fd=6),("httpd",pid=5214,fd=6),("httpd",pid=5213,fd=6),("httpd",pid=5212,fd=6)) tcp ESTAB 0 0 ::ffff:192.168.2.1:443 ::ffff:xxx.xxx.xxx.xxx(ルータIP):51711 users:(("httpd",pid=5216,fd=19)) tcp TIME-WAIT 0 0 ::ffff:192.168.2.1:443 ::ffff:xxx.xxx.xxx.xxx(ルータIP):51708 tcp TIME-WAIT 0 0 ::ffff:192.168.2.1:443 ::ffff:xxx.xxx.xxx.xxx(ルータIP):51710 tcp TIME-WAIT 0 0 ::ffff:192.168.2.1:443 ::ffff:xxx.xxx.xxx.xxx(ルータIP):51709 [root@www ~]#
stargryps

2018/10/15 08:05 編集

Include conf.modules.dについては、モジュールconfファイルを選別せず、 Include conf.modules.d/*.confという標準状態に戻してやってみます。 ->だめでしたー。結果変わらず。
ssasaki

2018/10/15 08:21

443でListenはしているみたいですね。 念のため、以下のコマンドを実行して、conf, module の情報を確認してみてください。 httpd -t -D DUMP_INCLUDES httpd -t -D DUMP_MODULES
stargryps

2018/10/15 08:41

ssasakiさん コマンドの結果です。 [root@www ~]# httpd -t -D DUMP_INCLUDES Included configuration files: (*) /etc/httpd/conf/httpd.conf (56) /etc/httpd/conf.modules.d/00-base.conf (56) /etc/httpd/conf.modules.d/00-dav.conf (56) /etc/httpd/conf.modules.d/00-lua.conf (56) /etc/httpd/conf.modules.d/00-mpm.conf (56) /etc/httpd/conf.modules.d/00-optional.conf (56) /etc/httpd/conf.modules.d/00-proxy.conf (56) /etc/httpd/conf.modules.d/00-ssl.conf (56) /etc/httpd/conf.modules.d/00-systemd.conf (56) /etc/httpd/conf.modules.d/01-cgi.conf (362) /etc/httpd/conf.d/autoindex.conf (362) /etc/httpd/conf.d/rewrite.conf (362) /etc/httpd/conf.d/ssl.conf (362) /etc/httpd/conf.d/userdir.conf (362) /etc/httpd/conf.d/welcome.conf [root@www ~]# httpd -t -D DUMP_MODULES Loaded Modules: core_module (static) so_module (static) http_module (static) access_compat_module (shared) actions_module (shared) alias_module (shared) allowmethods_module (shared) auth_basic_module (shared) auth_digest_module (shared) authn_core_module (shared) authn_dbd_module (shared) authn_dbm_module (shared) authn_file_module (shared) authn_socache_module (shared) authz_core_module (shared) authz_dbd_module (shared) authz_dbm_module (shared) authz_groupfile_module (shared) authz_host_module (shared) authz_owner_module (shared) authz_user_module (shared) cache_module (shared) cache_disk_module (shared) cache_socache_module (shared) data_module (shared) dbd_module (shared) deflate_module (shared) dir_module (shared) dumpio_module (shared) echo_module (shared) env_module (shared) expires_module (shared) ext_filter_module (shared) filter_module (shared) headers_module (shared) include_module (shared) info_module (shared) log_config_module (shared) logio_module (shared) macro_module (shared) mime_magic_module (shared) mime_module (shared) negotiation_module (shared) remoteip_module (shared) reqtimeout_module (shared) request_module (shared) rewrite_module (shared) setenvif_module (shared) slotmem_plain_module (shared) slotmem_shm_module (shared) socache_dbm_module (shared) socache_memcache_module (shared) socache_shmcb_module (shared) status_module (shared) substitute_module (shared) suexec_module (shared) unique_id_module (shared) unixd_module (shared) version_module (shared) vhost_alias_module (shared) watchdog_module (shared) mpm_prefork_module (shared) proxy_module (shared) proxy_connect_module (shared) proxy_http_module (shared) ssl_module (shared) systemd_module (shared) 以上です。
stargryps

2018/10/16 06:42

一部、自己解決しました。 まず、ssl.confに「SSLEngine one」の設定が入っていないことが分かりました。 役割は違うとはいえ、SSLProxyEngine onは入っていたので、これに気づくまで時間がかかってしまいました。 さらに、強制的にリダイレクトさせるように80番のバーチャルホストの設定をバッサリ削除しました。 以上の2点を実施、Apacheの再起動を行ったことでhttp://www.test.com->https://www.test.comにリダイレクトされるようになりました。 現在、https://home.test.comだけ接続することが出来ない状態まで持ってくることが出来ました。 これについてはおそらくバーチャルホストの設定にミスがあるんだろうと考えております。 タイトルの問題については解決いたしましたので、この質問についてはクローズさせていただこうと思います。ssasakiさんありがとうございました。
guest

0

ssasaki様

ご指摘ありがとうございます。
タイプミスでした。
設定上はHTTP_HOSTとなっております。

投稿2018/10/15 04:29

stargryps

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問