为SSL配置MAMP

问题描述 投票:36回答:6

好的编码人员,我正在尝试出于开发目的在Mac上使用SSL配置MAMP。我已阅读并尝试以下说明:http://www.emersonlackey.com/article/mamp-with-ssl-httpshttp://www.webopius.com/content/355/getting-mamp-working-with-ssl-on-os-x

没有运气。我可以用http命中127.0.0.1或localhost,但是https://localhosthttps://127.0.0.1都返回找不到主机错误。

看着phpinfo,我看不到mod_ssl正在加载。

有人用OS X 10.6.7做到了吗?我不知道从这里去哪里。

希望有人可以提供帮助。

感谢

----编辑开始------

以下是我对配置文件进行的更改,以使https工作。请按照上面列出的说明操作,以创建证书/密钥并删除密码(也由@dallas below提及)。

httpd.conf

注释掉ifdef以确保LoadModule被执行

#<IfDefine SSL>
    LoadModule ssl_module modules/mod_ssl.so
#</IfDefine>

确保文件中包含以下内容...

Listen 80
ServerName localhost:80

ssl.conf

添加以下内容...。

<VirtualHost localhost:443>
    DocumentRoot /Users/myname/Documents/DevProjects/WebdevProjects
    ServerName localhost
    SSLEngine on
    SSLCertificateFile /Applications/MAMP/conf/ssl/server.crt
    SSLCertificateKeyFile /Applications/MAMP/conf/ssl/server.key
</VirtualHost>

现有之前

<VirtualHost _default_:443>

server.crt和server.key是根据obove tut的链接新创建的。

评论

#<IfDefine SSL> 

第35行及其在第245行附近的结束标记以启用该行...

Listen 443

之间,根据上述VirtualHost定义将所有证书引用更新到新创建的文件。

apache ssl https mamp
6个回答
40
投票

如果使用的是MAMP 3或4],则说明略有不同。这是对我有用的方法,从没有Pro的Mavericks上全新安装MAMP 3.0.5开始。

更新:按照this answer中所述修复Apache后,仍可在优胜美地上使用。

进一步更新:评论表明,至少通过MAMP 5.4

,它仍然可以正常工作。

生成证书

此部分直接来自教程,因此,如果您已经做过,则可以跳至“设置MAMP”。

使用终端在您的默认文件夹中生成私钥:

cd ~
# generate a private key
openssl genrsa -des3 -out server.key 2048
# make up a passphrase and remember it, you’ll need it 3 more times.

# generate certificate signing request
openssl req -new -key server.key -out server.csr
# same password
# answer the questions, use "localhost" for your Common Name
Country Name: US
State Name: California
Locality: My City
Organization: My Company
Organization Unit Name: # leave blank
Common Name: localhost
Email address: [email protected]
A challenge password: # leave blank
An optional company name: # leave blank

# generate the certificate from the CSR for 5 years
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt

# remove the password requirement from the server key
cp server.key server.tmp
openssl rsa -in server.tmp -out server.key

设置MAMP 3.0.5

这里是以前版本的说明略有偏离。文件名和位置已更改,并且conf文件中的某些命令不同。以下是对我全新安装的MAMP 3.0.5的工作。

将证书文件(server.key和server.crt)移动到:

/ Applications / MAMP / conf / apache /

打开Apache的httpd.conf文件:

/ Applications / MAMP / conf / apache / httpd.conf

# set your listen port to 80 (near the top of the file)
Listen 80

# set your ServerName to localhost:80 (default is 8888)
ServerName localhost:80

# uncomment the line that includes the secure (SSL/TLS) connection conf
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

保存并关闭。现在打开Apache的ssl conf文件:

/ Applications / MAMP / conf / apache / extra / httpd-ssl.conf

找到<VirtualHost>条目(文件末尾的大块,以<VirtualHost _default_:443>开头,以</VirtualHost>结尾,然后将整个内容替换为:]

<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /Applications/MAMP/conf/apache/server.crt
        SSLCertificateKeyFile /Applications/MAMP/conf/apache/server.key
</VirtualHost>

保存并关闭。启动您的MAMP服务器。您应该可以通过http://localhosthttps://localhost访问文档根目录。


25
投票

这是https的非常困难的方法,很简单。


3
投票

我只是遇到了同样的问题,但是能够解决它。


1
投票

我也遵循了webopius的说明,但是无法加载SSL页面。如@djeetee所述,httpd.conf和ssl.conf中虚拟服务器的定义是有问题的。我发现best guide建议对这些文件进行以下修订:


1
投票

还请确保您取消注释httpd.conf中的这一行


1
投票

如果您正在使用MAMP 4,但仍在努力使ssl正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.