apache - 为 SSL 配置 MAMP

标签 apache ssl https mamp

各位编码员,出于开发目的,我正在尝试在我的 Mac 上使用 SSL 配置 MAMP。我已阅读并尝试了以下说明:
http://www.emersonlackey.com/article/mamp-with-ssl-https http://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 正常工作而对配置文件所做的更改。请按照上面列出的步骤创建证书/ key 并删除密码(同样由 @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 是根据上面的 tuts 链接新创建的。

注释掉

#<IfDefine SSL> 

围绕第 35 行及其结束标记围绕第 245 行启用该行...

Listen 443

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

最佳答案

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

更新:在按照 this answer 中所述修复 Apache 后,仍然可以在 Yosemite 上运行.

进一步更新:评论表明这至少在 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@example.com
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://localhost 访问您的文档根目录和 https://localhost .

关于apache - 为 SSL 配置 MAMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6318467/

相关文章:

使用 AWS Elastic Load Balancing 的 SSL - 静态 IP?

java - 无法发布 Twitter 状态更新,错误为 "no trusted certificate found"

ruby-on-rails - 通过 HTTPS 发布 Ruby on Rails

node.js - 代理后面的 nodejs 的简单示例

php - Apache:内联 PHP 无法在 Linux 上运行

java - SSL 连接重置

php - Apache webroot 图标未加载

ssl - 如何通过 HTTPS/SSL 运行 Svelte/Sapper 应用程序?

apache - 跨域策略允许 Youtube

apache - 连接到上游时连接被拒绝 - Docker