Jonny Nott
Jonny Nott

Reputation: 326

Running SSL and non-SSL sites simultaneously with MAMP (4.0.6)

To enable SSL, I've uncommented this line in httpd.conf:

# Secure (SSL/TLS) connections
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

The httpd-ssl.conf file itself I've left untouched, and created .crt and .key files for a self-signed SSL certificate in the places it's expecting to see them by default:

SSLCertificateFile "/Applications/MAMP/conf/apache/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/server.key"

Back in the main httpd.conf, I've created a VirtualHost for a site I want to use SSL, and configured like this to eventually get it working:

NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Users/jonnott/Documents/sslsite1.dev"
ServerName sslsite1.dev:443
ServerAlias www.sslsite1.dev
SSLEngine on
SSLCertificateFile "/Applications/MAMP/conf/apache/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/server.key"
</VirtualHost>

This SSL site now works fine.

However, the problem I have is that now whenever I try to visit any local non-SSL hosts, I get this error:

Bad Request

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.

These other non-SSL sites are configured in httpd.conf like this:

<VirtualHost *> 
DocumentRoot "/Users/jonnott/Documents/site2.dev"
ServerName site2.dev
ServerAlias www.site2.dev
</VirtualHost>

What am I missing / doing wrong?

Upvotes: 1

Views: 1016

Answers (1)

Jonny Nott
Jonny Nott

Reputation: 326

I think I've pretty much figured it out after reading this:

http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#vhosts2

I needed BOTH of these in my httpd.conf before the start of my VirtualHost directives:

NameVirtualHost *:80
NameVirtualHost *:443

..and then each VirtualHost needed to be port-specific:

<VirtualHost *:80>
DocumentRoot "/Users/jonnott/Documents/Projects/site1"
ServerName site1.dev:80
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/Users/jonnott/Documents/Projects/site1"
ServerName site1.dev:443
SSLEngine on
SSLCertificateFile "/Applications/MAMP/conf/apache/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/server.key"
</VirtualHost>

Upvotes: 2

Related Questions