I’ve been trying to configure my MAMP installation (NOT the paid version) to accept SSL for a recent project that I am working on. A lot of MAMP SSL tutorials are out dated and do not work for MAMP v2+ (2.0.5) and some just don’t seem to work so I had to do a lot of digging around.
Non-SSL traffic results in 400 error
My main problem was that all traffic was forced via SSL – http traffic was met with a 400 error. I only wanted part of my project to run on SSL.
Setting up MAMP for SSL – the basics
I found this site that helped with the bulk of the task of how to implement MAMP SSL:
It covers the following steps:
- Back up your MAMP install, or at least your config files
- Generate a self signed certificate to use in your dev environment
- Uncomment the required lines in the httpd.conf
- Define your SSL site in httpd-ssl.conf
It also covers editing your hosts file and setting up virtual hosts – useful if you are a first timer at this and something I have previously covered.
I won’t cover these parts again, but I will add some important extra info that solved some key issues that I ran into:
MAMP SSL Problems
First, uncommenting and using the httpd-vhosts.conf file does not seem to work for me. For some reason apache would not start despite much fettling with the virtual host declarations in the file. Not a problem, you don’t need it – just leave this line commented and define your virtual hosts at the bottom of the httpd.conf file.
Fixing MAMP config: non-SSL http 400 error
The big issue for me is that enabling SSL results in only SSL traffic being accepted by the server, so if you try to access your site using http://.. you will receive a 400 ‘bad request’ http error message. To enable non-http traffic to work, you must do the following:
In httpd.conf, instead of:
You have to be explicit in the site you are defining in the <VirtualHost> tag. You also need to declare ‘SSLDisable’.
This allows your test site to accept both ssl and non-SSL traffic.
One other interesting point that may be important if you want to run multiple SSL sites on MAMP:
In the Apache docs it states that name based virtual hosts do not work for SSL. You can have one SSL site and multiple non-SSL sites defined via virtual hosts, but for multiple SSL sits you must use IP-based virtual hosts – so you would have to configure the machine with multiple IPs. Probably not worth bothering with!.
Key to finding out how to solve my 404 issue was this example settings page that shows how to set up a site on ssl and another, differently addressed non-SSL site, but the principles are largely the same.
Posted from London, England, United Kingdom.