apache 使用 MAMP 测试 HTTPS 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:42:47  来源:igfitidea点击:

Testing HTTPS files with MAMP

apachemacossslhttpsmamp

提问by jgreenawalt

I am running MAMP locally on my laptop, and I like to test as much as I can locally. Unfortunately, since I work on e-commerce stuff (PHP), I normally force ssl in most of the checkout forms and it just fails on my laptop. Is there any easy configuration that I might be missing to allow "https" to run under MAMP? Please note, I know that I couldconfigure Apache by hand, re-compile PHP, etc. but I'm just wondering if there's an easier way for a lazy programmer.

我在我的笔记本电脑上本地运行 MAMP,我喜欢在本地尽可能多地进行测试。不幸的是,由于我从事电子商务方面的工作 (PHP),我通常在大多数结帐表单中强制使用 ssl,但它在我的笔记本电脑上失败了。是否有任何简单的配置我可能会遗漏以允许“https”在 MAMP 下运行?请注意,我知道我可以手动配置 Apache、重新编译 PHP 等,但我只是想知道对于懒惰的程序员是否有更简单的方法。

Thanks

谢谢

采纳答案by Rodney Amato

NOTE: startssl is no longer supported after version 2+ of MAMP. You have to update the config files (httpd.conf) to enable ssl.

注意:在 MAMP 2+ 版本之后不再支持startssl。您必须更新配置文件 (httpd.conf) 才能启用 ssl。

You can modify the free version of MAMP to enable ssl by default very easily. Once you have setup all the SSL parts of apache and have it working so that calling apachectl startssl works, just edit the file

您可以修改 MAMP 的免费版本以非常轻松地默认启用 ssl。一旦你设置了 apache 的所有 SSL 部分并让它工作以便调用 apachectl startssl 工作,只需编辑文件

/Applications/MAMP/startApache.sh

in your favorite text editor and change the startargument to startssland you will have the MAMP launcher starting apache in ssl mode for you.

在您最喜欢的文本编辑器中,将start参数更改为startssl,您将拥有 MAMP 启动器以 ssl 模式为您启动 apache。

回答by Riley

First, make a duplicate of /Applications/MAMP.

首先,复制/Applications/MAMP。

Open /Applications/MAMP/conf/apache/httpd.conf
Below the line
# LoadModule foo_module modules/mod_foo.so
you add
LoadModule ssl_module modules/mod_ssl.so
Remove all lines <IfDefine SSL>as well as </IfDefine SSL>.

打开 /Applications/MAMP/conf/apache/httpd.conf

# LoadModule foo_module modules/mod_foo.so
您添加的行下方
LoadModule ssl_module modules/mod_ssl.so
删除所有行<IfDefine SSL>以及</IfDefine SSL>.

Open /Applications/MAMP/conf/apache/ssl.conf
Remove all lines <IfDefine SSL>as well as </IfDefine SSL>.
Find the line defining SSLCertificateFileand SSLCertificateKeyFile, set it to
SSLCertificateFile /Applications/MAMP/conf/apache/ssl/server.crtSSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl/server.key

打开 /Applications/MAMP/conf/apache/ssl.conf
删除所有行<IfDefine SSL>以及</IfDefine SSL>.
找到定义SSLCertificateFile和的行SSLCertificateKeyFile,将其设置为
SSLCertificateFile /Applications/MAMP/conf/apache/ssl/server.crtSSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl/server.key

Create a new folder /Applications/MAMP/conf/apache/ssl
Drop into the terminal an navigate to the new folder
cd /Applications/MAMP/conf/apache/ssl
Create a private key, giving a password
openssl genrsa -des3 -out server.key 1024
Remove the password
cp server.key server-pw.key
openssl rsa -in server-pw.key -out server.key
Create a certificate signing request, pressing return for default values
openssl req -new -key server.key -out server.csr
Create a certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

创建一个新文件夹 /Applications/MAMP/conf/apache/ssl
放入终端并导航到新文件夹
cd /Applications/MAMP/conf/apache/ssl
创建私钥,提供密码
openssl genrsa -des3 -out server.key 1024
删除密码
cp server.key server-pw.key
openssl rsa -in server-pw.key -out server.key
创建证书签名请求,按返回默认值
openssl req -new -key server.key -out server.csr
创建证书
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Restart your server. If you encounter any problems check the system log file. The first time you visit https://localhost/you will be asked to accept the certificate.

重新启动您的服务器。如果遇到任何问题,请检查系统日志文件。第一次访问时,https://localhost/您将被要求接受证书。

回答by David Crow

There doesn't seem to be an easier way, unless you're willing to buy MAMP Pro.

似乎没有更简单的方法,除非您愿意购买 MAMP Pro

As far as I know, the only way to use SSL with MAMP is to configure mod_ssl for Apache. mod_ssl is bundled with MAMP, and I found configuration to be pretty straightforward. Note that you'll probably have to start Apache from the command line to use it:

据我所知,将 SSL 与 MAMP 一起使用的唯一方法是为 Apache 配置 mod_ssl。mod_ssl 与 MAMP 捆绑在一起,我发现配置非常简单。请注意,您可能必须从命令行启动 Apache 才能使用它:

/Applications/MAMP/bin/apache2/bin$ ./apachectl stop
/Applications/MAMP/bin/apache2/bin$ sudo ./apachectl startssl