我只想使用以下命令打开我的网站登录页面https
,我检查服务器上是否启用了 SSL,以下是服务器返回的基本信息phpinfo()
;
PHP Version 5.2.14
Configure Command '--with-openssl' '--enable-zip'
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
curl
cURL support enabled
cURL Information libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.2.3
openssl
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.7a Feb 19 2003
我的基本代码header.php
是
if($_SERVER['SERVER_PORT'] != 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
但它总是给出以下错误:
连接已
超时 www.mywebsite.com 的服务器响应时间过长。
localhost
尽管相同的代码在...phpinfo()
返回时完美运行
PHP version 5.3.1
openssl
OpenSSL support enabled
OpenSSL Library Version OpenSSL 0.9.8l 5 Nov 2009
OpenSSL Header Version OpenSSL 0.9.8l 5 Nov 2009
我有 2 个问题
- 我需要更新我的 SSL 吗?或者我如何在https在服务器上???
- 如何只打开 2 个页面https其余内容都在 http 中
谢谢
答案1
首先创建 openssl 证书,获取帮助这个博客
然后对以下文件进行必要的更改
这里我还包括如何为虚拟主机设置 https
/opt/lampp/etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin localhost.admin
DocumentRoot "/opt/lampp/htdocs/"
ServerName localhost
ErrorLog "logs/php_error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/wish"
ServerName ice.cold.com
ServerAlias www.ice.cold.com
<Directory /opt/lampp/htdocs/wish>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/ice.cold-error_log"
CustomLog "logs/ice.cold-access_log" common
</VirtualHost>
/opt/lampp/etc/extra/httpd-ssl.conf
<VirtualHost _default_:443>
DocumentRoot "/opt/lampp/htdocs"
ServerName localhost:443
ServerAdmin localhost.admin
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/opt/lampp/etc/ssl.crt/server.crt"
SSLCertificateKeyFile "/opt/lampp/etc/ssl.key/server.key"
</VirtualHost>
<VirtualHost ice.cold.com:443>
# General setup for the virtual host
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/wish"
ServerName ice.cold.com
ServerAlias www.ice.cold.com
<Directory /opt/lampp/htdocs/wish>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/ice.cold-error_log"
CustomLog "logs/ice.cold-access_log" common
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/opt/lampp/etc/ssl.crt/server.crt"
SSLCertificateKeyFile "/opt/lampp/etc/ssl.key/server.key"
答案2
如果网站远程超时,但通过本地主机访问时可以正常运行,通常意味着防火墙配置错误。请检查端口 443 是否对外界开放。