跟大家講解下有關關于php設置https的問題,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說關于php設置https的問題,小編也收集到了有關關于php設置https的問題的相關資料,希望大家看到了會喜歡。
php設置https的方法:首先設置“httpd.ini”并添加相關配置;然后將“httpd-ssl.conf”里面的“VirtualHost”配置完整路徑;最后使http重定向到https即可。
推薦:《PHP視頻教程》
設置https以及http轉https的問題
公司用的是阿里云服務器win2008server r2 ,環境是phpwamp,出現許多問題。2018-11-12
一 設置https
1、設置httpd.ini 取消以下三個配置的#
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so LoadModule ssl_module modules/mod_ssl.so Include conf/extra/httpd-ssl.conf2、并且注意 httpd-ssl.conf里面的VirtualHost配置要用完整路徑,支持多個https同時使用
例如這樣既可:
#百度官方網站<VirtualHost *:443> DocumentRoot "D:/WWW/baidu/public/" ServerName www.baidu.com:443 SSLEngine on SSLCertificateFile D:/ssl/www.baidu.com/www.baidu.com.cer SSLCertificateKeyFile D:/ssl/www.baidu.com/www.baidu.com.key SSLCertificateChainFile D:/ssl/www.baidu.com/www.baidu.com_ca.crt </VirtualHost>#淘寶官方網站<VirtualHost *:443> DocumentRoot "D:/WWW/taobao/public/" ServerName www.taobao.com:443 SSLEngine on SSLCertificateFile D:/ssl/www.taobao.com/www.taobao.com.cer SSLCertificateKeyFile D:/ssl/www.taobao.com/www.taobao.com.key SSLCertificateChainFile D:/ssl/www.taobao.com/www.taobao.com_ca.crt </VirtualHost><VirtualHost _default_:443> DocumentRoot "C:/*****/PHPWAMP_IN2/wwwroot/test" ServerName www.test.com:443 ServerAlias test.com DirectoryIndex index.html index.htm index.php default.php app.php u.php ErrorLog logs/example_error.log CustomLog logs/example_access.log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" SSLEngine on SSLCertificateFile "C:/**************.com_public.crt" SSLCertificateKeyFile "C:/**********.com.key" SSLCertificateChainFile "C:/*****.com_chain.crt"<Directory "C:/*****/PHPWAMP_IN2/wwwroot/test"> SSLOptions +StdEnvVars AllowOverride All Require all granted</Directory><FilesMatch "\.(shtml|phtml|php)$"> SSLOptions +StdEnvVars</FilesMatch> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0</VirtualHost>上圖是phpwamp軟件配置ssl的代碼(***是目錄路徑和文件名 ,這里抹除)
最后要注意的是,查看httpd-ssl.conf文件里面所使用的443端口是否被占用,如果被占用Apache也會啟動失敗。
3、因為是阿里云服務器,所有需要在阿里云后臺管理開啟443端口
4、在服務器上的防火墻增加入站規則 443
留意SSLCertificateChainFile的地址配置,三個ssl路徑地址中任何一個路徑錯誤都會造成apache的啟動失敗,如有問題,請重點排查這處。
二 http重定向到https
當你的站點使用了HTTPS之后,你可能會想把所有的HTTP請求(即端口80的請求),全部都重定向至HTTPS(即端口443)。這時候你可以用以下的方式來做到:(Apache mod_rewrite)
把這段代碼放在.htaccess文件(網站根目錄下),即可實現HTTP到HTTPS的重定向。
<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://www.baidu.com/$1 [R=301,L]</IfModule>而當你又想用回HTTP的時候,反過來就可以了:
<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{SERVER_PORT} 443RewriteRule ^(.*)$ https://www.baidu.com/$1 [R=301,L]</IfModule>其中R=301表示Moved Permanently,即告訴搜索引擎或者瀏覽器下去直接訪問后者的地址,
如果只是試驗性地重定向,可以使用R=302(Found),臨時跳轉
以上就是關于php設置https的問題的詳細內容,更多請關注php中文網其它相關文章!
來源:php中文網