为什么https不工作?

我正在尝试将我的网站的根目录redirect到https。 虽然重写发生,但https不会产生任何结果。 浏览器说。 connecting to thinkingmonkey.me...并停滞不前。

  • Listen 80Listen 443出现在conf文件中。
  • 我重新启动了httpd
  • 我正在使用正确的证书文件和私钥文件。
  • httpd日志中没有错误, SSL日志 (我有一个单独的日志SS1)。
  • 从字面上看,即使我尝试直接访问https://thinkingmonkey.me,也没有logging到SSL访问日志中。

一个netstat -pant | grep httpd netstat -pant | grep httpd有这样的:

 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 :::443 :::* LISTEN 1334/httpd tcp 0 0 :::80 :::* LISTEN 1334/httpd 

的.htaccess:

 RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^(.*)$ https://thinkingmonkey.me [L,R=302] 

重写数据:

my_ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](2)init用请求的uri /

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](1)通过/

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](3)[perdir / mysite /] strip per-dir prefix :/ mysite / – >

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](3)[perdir / mysite /] apply pattern'^( 。*)$'to uri''

my_ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](4)[perdir / mysite /] RewriteCond:input =' 80'pattern = '80'=>匹配

my_ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](4)[perdir / mysite /] RewriteCond:input =' /'pattern ='^ / $'=>匹配

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](2)[perdir / mysite /] rewrite'' – > ' https://thinkingmonkey.me '

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](2)[perdir / mysite /]显式强制使用httpsredirect://thinkingmonkey.me

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](1)[perdir / mysite /]转义https:// thinkingmonkey.meredirect

my-ip – [24 / Jan / 2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial](1)[perdir / mysite /]redirect到https:/ /thinkingmonkey.me [REDIRECT / 302]

这是我的虚拟主机。

 <VirtualHost *:80> ServerName thinkingmonkey.com ServerAlias www.thinkingmonkey.com www.thinkingmonkey.me RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?thinkingmonkey\.(com|me)$ [NC] RewriteRule ^ http://thinkingmonkey.me%{REQUEST_URI} [L,R=301] </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /mysite/ ServerName thinkingmonkey.me ErrorLog logs/site-error_log CustomLog logs/site-access_log common RewriteEngine On RewriteLog "/var/log/rewrite.log" RewriteLogLevel 3 </VirtualHost> <VirtualHost *:443> ServerName thinkingmonkey.me ErrorLog logs/ssl_error_log TransferLog logs/ssl_access_log LogLevel warn SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW SSLCertificateFile /path/to/my.crt SSLCertificateKeyFile /path/to/my.key SSLCertificateChainFile /path/to/my.ca-bundle <Files ~ "\.(cgi|shtml|phtml|php3?)$"> SSLOptions +StdEnvVars </Files> <Directory "/var/www/cgi-bin"> SSLOptions +StdEnvVars </Directory> SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog logs/ssl_request_log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost> 

 lsof -i -P | grep 443 httpd 1334 root 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1335 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1336 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1337 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1338 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1339 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1340 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1341 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) httpd 1342 apache 6u IPv6 3297 0t0 TCP *:443 (LISTEN) 

这里怎么了?

好的,试试这个:

 telnet localhost 443 

这是回应,还是挂起? 如果它的响应,你应该得到的东西看起来像:

 $ telnet localhost 443 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 

(如果没有安装telnet,那么安装它;你可以通过点击control-]来退出telnet会话,然后input“q”退出)

如果你能够连接到本地接口上的Web服务器(并且Web服务器正在运行,给定你的日志),那么存在防火墙问题(我知道你说过没有设置防火墙,但是这样做会确认)。 在这种情况下,运行:

 iptables -L -n 

并发布结果。

更新

从注释,这是一个EC2实例,所以看看与这个实例相关的安全组。 确保你的安全组允许tcp / 443。

像这样的东西可能会有所帮助:

http://cloud-computing.learningtree.com/2010/09/24/understanding-amazon-ec2-security-groups-and-firewalls/

在双堆栈主机上,侦听:: 443意味着您正在侦听IPv4和IPv6。 自己testingTLS协商:

 openssl s_client -connect localhost:443 [lots of negotiation output, to ensure the basics are there] 

然后,您将能够testingHTTP回复:

 GET / HTTP/1.0 

以下是我将如何redirect:

 <VirtualHost *:80> ServerName mail.example.com RewriteEngine On RewriteLog /var/log/apache2/rewrite.log RewriteLogLevel 4 RewriteRule ^(.*)$ https://secure.example.com/mail$1 [R,L] </VirtualHost> 

请删除生产中的RewriteLogRewriteLogLevel ,否则可能无意识地填充磁盘。

打开httpd.conf ,看看下面的行是否存在:

 LoadModule ssl_module modules/mod_ssl.so 

如果没有,那么用这个更新httpd.conf并重新启动Apache。

类似的问题,apache2是响应443,没有在日志中

 /etc/apache2# openssl s_client -connect localhost:443 -state -debug 

给了我以下

 SSL_connect:unknown state read from 0x1182fe0 [0x1189010] (7 bytes => 7 (0x7)) 0000 - 48 54 54 50 2f 31 2e HTTP/1. SSL_connect:error in unknown state 139790287365792:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:795: --- no peer certificate available --- No client certificate CA names sent --- SSL handshake has read 7 bytes and written 295 bytes --- New, (NONE), Cipher is (NONE) Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE 

问题是my.domain.com是一个不同于在虚拟主机中configuration的ip。 由于服务器使用2个IP。 所以apache在443应答,但不能连接一个网站的连接。 匹配的IP都很好

值得仔细检查一下您的提供商提供的SSL策略。 经过大量的debugging,我发现我的问题是由我的托pipe服务提供商locking443端口,直到我付了SSL证书。 我一直计划使用LetsEncrypt,但是我必须先切换主机才能做到这一点。 无论如何,如果没有其他解决scheme可以帮助您,并且您处于VPS环境(或者您可能对networking控制较less的任何环境),则可能需要仔细检查这一点。