How to Configure Multiple IP Addresses for Localhost on OS X 10.6 for HTTPS Web Development


2 views

When developing multiple HTTPS websites locally, each site typically requires its own IP address or port combination. Since HTTPS traditionally uses port 443, assigning different IPs to localhost becomes the cleanest solution for development environments.

OS X's network configuration allows creating virtual interfaces through the ifconfig command. Here's how to add additional loopback addresses:


sudo ifconfig lo0 alias 127.0.0.2 up
sudo ifconfig lo0 alias 127.0.0.3 up

These changes are temporary and will reset after reboot. To make them persistent, create a launchd daemon:






    Label
    com.user.lo0-aliases
    ProgramArguments
    
        /sbin/ifconfig
        lo0
        alias
        127.0.0.2
        up
    
    RunAtLoad
    


With the IPs configured, modify your MAMP setup:


# For Apache Virtual Hosts

    ServerName site1.dev
    DocumentRoot "/path/to/site1"



    ServerName site2.dev
    DocumentRoot "/path/to/site2"

For HTTPS development, you'll need to:

  1. Generate separate SSL certificates for each IP
  2. Configure Apache to listen on each IP:port combination
  3. Update your hosts file with domain mappings

# Example hosts file entries
127.0.0.2    site1.dev
127.0.0.3    site2.dev

Verify the configuration by running:


curl -I http://site1.dev
curl -I https://site1.dev
ping site1.dev

When developing multiple HTTPS websites locally on OS X 10.6 with MAMP, you'll quickly encounter certificate limitations. Each SSL certificate typically requires its own IP address due to how HTTPS works at the protocol level before SNI became widely supported.

OS X makes it straightforward to add additional loopback addresses. Open Terminal and run:


sudo ifconfig lo0 alias 127.0.0.2 up
sudo ifconfig lo0 alias 127.0.0.3 up

This creates two additional IP addresses (127.0.0.2 and 127.0.0.3) that resolve to your local machine.

To ensure these aliases survive reboots, create a launch daemon:


sudo nano /Library/LaunchDaemons/com.user.lo0.aliases.plist

Add this content:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.lo0.aliases</string>
    <key>ProgramArguments</key>
    <array>
        <string>/sbin/ifconfig</string>
        <string>lo0</string>
        <string>alias</string>
        <string>127.0.0.2</string>
        <string>up</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Edit your httpd.conf (typically at /Applications/MAMP/conf/apache/httpd.conf) and add:


Listen 127.0.0.1:80
Listen 127.0.0.2:80
Listen 127.0.0.3:80

Then configure virtual hosts for each IP:


<VirtualHost 127.0.0.1:80>
    ServerName site1.local
    DocumentRoot "/Applications/MAMP/htdocs/site1"
</VirtualHost>

<VirtualHost 127.0.0.2:80>
    ServerName site2.local
    DocumentRoot "/Applications/MAMP/htdocs/site2"
</VirtualHost>

For SSL, you'll need to modify the SSL configuration similarly:


Listen 127.0.0.1:443
Listen 127.0.0.2:443

<VirtualHost 127.0.0.1:443>
    SSLEngine on
    SSLCertificateFile "/path/to/site1.crt"
    SSLCertificateKeyFile "/path/to/site1.key"
    ServerName site1.local
    DocumentRoot "/Applications/MAMP/htdocs/site1"
</VirtualHost>

After restarting MAMP, test your setup by pinging the new addresses:


ping 127.0.0.2
ping 127.0.0.3

Then edit your /etc/hosts file to point your development domains to these IPs:


127.0.0.1 site1.local
127.0.0.2 site2.local
127.0.0.3 site3.local