我在Ubuntu 12.04上运行Apache 2.4.7。 我有一个网站http://bharatkrishna.net/ ,这是在我家里跑掉一台机器。 我在路由器上转发了端口80和443。
正如你所看到的,当你访问http://bharatkrishna.net/时 ,它会自动被redirect到https://bharatkrishna.net/ 。
我不希望它被redirect到整个网站的https。 我本来打算只为一个特定的子url。 即。 像只有http://bharatkrishna.net/login应该是https,其余的应该是http。 我该怎么做?
这是我通过在线阅读一些教程在Apache上设置SSL的方法:
•在/ etc / apache2 / sites-enabled /打开SSLEngine,设置证书位置
<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/ #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # SSL Engine Switch: # Enable/Disable SSL for this virtual host. SSLEngine on SSLCertificateFile /etc/apache2/ssl/www_bharatkrishna_net.crt SSLCertificateKeyFile /etc/apache2/ssl/bharatkrishna.net.key SSLCACertificatePath /etc/ssl/certs/ SSLCACertificateFile /etc/apache2/ssl/bundle.crt .... .... </VirtualHost> </IfModule>
•运行以下命令:
sudo a2enmod ssl sudo a2ensite default-ssl
我将000-default.conf复制到启用了sites的default.conf ,这里是文件的内容:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
为Apache发布的configuration不会执行从http到https任何redirect。 在这种情况下,切换到https是由浏览器完成的。
有关此行为的更多信息,请参见: