我有一个运行Apache / 2.4.18(Ubuntu)的Ubuntu 16.04服务器。 我从github安装了let-encrypt并运行./letsencrypt-auto --apache ,从下面的对话框中select第二个选项:
Please choose whether HTTPS access is required or optional. ------------------------------------------------------------------ 1: Easy - Allow both HTTP and HTTPS access to these sites 2: Secure - Make all requests redirect to secure HTTPS access ------------------------------------------------------------------
这导致了这个消息
Congratulations! You have successfully enabled my.own.server.tld
并自动生成虚拟主机文件。 然后我重新启动服务器。
我试图访问我的网站,这与http(没有问题),但与https(Firefox和Chrome尝试加载页面,超过两分钟后超时)。 我预计这个网站只能通过https访问,或者至less可以通过https访问。
/etc/apache2/sites-enabled/只有一个文件:
my.own.server.tld-le-ssl.conf
<IfModule mod_ssl.c> <VirtualHost *:443> ServerName my.own.server.tld ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLCertificateFile /etc/letsencrypt/live/my.own.server.tld/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/my.own.server.tld/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>
/etc/letsencrypt/options-ssl-apache.conf也是通过let-encrypt自动生成的,看起来像
SSLEngine on # Intermediate configuration, tweak to your needs SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:... SSLHonorCipherOrder on SSLCompression off SSLOptions +StrictRequire # Add vhost name to log entries: LogFormat "..." vhost_combined LogFormat "..." vhost_common
...部分不是字面上的文件 – 我只是省略了这些部分,使这个问题更具可读性。
a2enmod ssl (打印Module ssl already enabled )。 <Directory /> SSLRequireSSL </Directory> 。 (没有改变任何东西,网站仍然可以通过http访问,但是不能通过https访问) SSLRequireSSL写入/var/www/html/.htaccess 。 (没有改变任何东西,网站仍然可以通过http访问,但是不能通过https访问) 服务器my.own.server.tld正在我的大学运行。 我只控制my部分,既不知道也不控制底层系统,但我想我的服务器是一个OpenStack实例。 服务器应该只有一个IP。
apache2ctl -S打印
VirtualHostconfiguration: *:443 my.own.server.tld(/etc/apache2/sites-enabled/my.own.server.tld-le-sll.conf:2) ServerRoot:“/ etc / apache2” Main DocumentRoot:“/ var / www / html” 主要ErrorLog:“/var/log/apache2/error.log” 互斥看门狗callback:using_defaults 互斥锁rewrite-map:using_defaults 互斥锁ssl-stapling-refresh:using_defaults 互斥锁ssl-stapling:using_defaults Mutex ssl-cache:using_defaults 互斥体默认:dir =“/ var / lock / apache2”mechanism = fcntl PidFile:“/var/run/apache2/apache2.pid” 定义:DUMP_VHOSTS 定义:DUMP_RUN_CFG 用户:name =“www-data”id = 33 组:name =“www-data”id = 33
netstat -pant | grep apache2 netstat -pant | grep apache2打印
tcp6 0 0 :::80 :::* LISTEN 8592/apache2 tcp6 0 0 :::443 :::* LISTEN 8592/apache2
netstat -l46n打印
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 :::443 :::* LISTEN udp 0 0 0.0.0.0:68 0.0.0.0:*
telnet localhost 443打印预期的输出。
iptables -L -n打印
Chain INPUT (policy ACCEPT) target prot opt source destination f2b-sshd tcp -- 0.0.0.0/0 0.0.0.0/0 multiport dports 22 Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain f2b-sshd (1 references) target prot opt source destination RETURN all -- 0.0.0.0/0 0.0.0.0/0
/var/log/apache2/error.log中没有错误。
尝试通过telnet连接到https端口,看它是否可以从服务器本身访问。 它应该如下所示:
$ telnet localhost 443 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'.
顺便说一下:如果你希望用户只通过https访问你的网站,你需要在http虚拟主机中configuration这样的东西,将它们redirect到https:
<VirtualHost *:80> ServerName my.own.server.tld ServerAlias www.my.own.server.tld RewriteEngine On RewriteCond %{SERVER_PORT} !443 RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{SERVER_NAME} =www.my.own.server.tld RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] </VirtualHost>
我通过certonly选项获得了我的证书。 然后修改你的Apache网站的定义是:
<VirtualHost _DEFAULT_:443> ServerName example.com ServerAlias www.example.com ServerAdmin [email protected] SSLEngine on SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown CustomLog ${APACHE_LOG_DIR}/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" DocumentRoot /var/www-example.com <directory /var/www-example.com> Options All AllowOverride All Require all granted </directory> ErrorLog ${APACHE_LOG_DIR}/ssl-example.com-error.log CustomLog ${APACHE_LOG_DIR}/ssl-example.com-access.log combined </VirtualHost>
然后在apache中启用SSL – a2enmod ssl – 然后重新启动apache2。
你显示的apache2ctl -S的输出看起来是正确的 – 如果你(重新)启动apache2,它显示为监听,如果你通过netstat -l46n看?
SSLCertificateFile /etc/letsencrypt/live/my.own.server.tld/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/my.own.server.tld/privkey.pem
pem文件只是一个容器文件,本身不是证书。 你将需要一个CRT文件。