use*_*025 19 php openssl localhost
操作系统: Ubuntu 12.04 64位
PHP版本: 5.4.6-2~precision + 1
当我测试一个https页面时,我正在通过内置的webserver(php5 -S localhost:8000)编写,Firefox(16.0.1)说"问题加载:连接被中断",而终端告诉我":: 1" :37026无效请求(不支持的SSL请求)".
phpinfo()告诉我:
OpenSSL的:
OpenSSL支持:已启用
OpenSSL库版本OpenSSL 1.0.1 2012年3月14日
OpenSSL标题版本OpenSSL 1.0.1 2012年3月14日
是的,http页面工作得很好.
有任何想法吗?
mar*_*rio 38
请参阅内置Web服务器垫片的手册部分:http:
//php.net/manual/en/features.commandline.webserver.php
它不支持SSL加密.它适用于普通的HTTP请求.在openssl扩展和功能的支持是不相关的.它不接受请求或通过流包装器发送响应.
如果您希望SSL在其上运行,请尝试使用stunnel包装器:
php -S localhost:8000 &
stunnel3 -d 443 -r 8080
Run Code Online (Sandbox Code Playgroud)
无论如何,这只是为了玩弄.
小智 11
距离上次更新已经三年了;以下是我如何让它在 2021 年在 macOS 上运行(作为马里奥答案的扩展):
# Install stunnel
brew install stunnel
# Find the configuration directory
cd /usr/local/etc/stunnel
# Copy the sample conf file to actual conf file
cp stunnel.conf-sample stunnel.conf
# Edit conf
vim stunnel.conf
Run Code Online (Sandbox Code Playgroud)
修改stunnel.conf成这样:(其他选项都可以删除)
; **************************************************************************
; * Global options *
; **************************************************************************
; Debugging stuff (may be useful for troubleshooting)
; Enable foreground = yes to make stunnel work with Homebrew services
foreground = yes
debug = info
output = /usr/local/var/log/stunnel.log
; **************************************************************************
; * Service definitions (remove all services for inetd mode) *
; **************************************************************************
; ***************************************** Example TLS server mode services
; TLS front-end to a web server
[https]
accept = 443
connect = 8000
cert = /usr/local/etc/stunnel/stunnel.pem
; "TIMEOUTclose = 0" is a workaround for a design flaw in Microsoft SChannel
; Microsoft implementations do not use TLS close-notify alert and thus they
; are vulnerable to truncation attacks
;TIMEOUTclose = 0
Run Code Online (Sandbox Code Playgroud)
它在端口 443 接受 HTTPS / SSL,并使用 stunnel 的默认伪造证书连接到在端口 8000 运行的本地 Web 服务器/usr/local/etc/stunnel/stunnel.pem。日志级别为info,日志输出写入到/usr/local/var/log/stunnel.log。
启动隧道:
; **************************************************************************
; * Global options *
; **************************************************************************
; Debugging stuff (may be useful for troubleshooting)
; Enable foreground = yes to make stunnel work with Homebrew services
foreground = yes
debug = info
output = /usr/local/var/log/stunnel.log
; **************************************************************************
; * Service definitions (remove all services for inetd mode) *
; **************************************************************************
; ***************************************** Example TLS server mode services
; TLS front-end to a web server
[https]
accept = 443
connect = 8000
cert = /usr/local/etc/stunnel/stunnel.pem
; "TIMEOUTclose = 0" is a workaround for a design flaw in Microsoft SChannel
; Microsoft implementations do not use TLS close-notify alert and thus they
; are vulnerable to truncation attacks
;TIMEOUTclose = 0
Run Code Online (Sandbox Code Playgroud)
启动网络服务器:
brew services start stunnel # Different for Linux
Run Code Online (Sandbox Code Playgroud)
现在您可以访问https://localhost:443您的网络服务器:截图
应该有一个证书错误,您必须单击浏览器警告,但这使您可以使用 HTTPS 请求访问本地主机以进行开发。