Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm attempting to host multiple website locally with HTTPS enabled, but in order to do this I'd need to configure my local machine to use multiple IP address for localhost (I believe). Is there any way to have multiple IP addresses resolving locally at the same time?

I am using OS X 10.6 (standard edition - not server), and the MAMP server setup.

Thanks!

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You don't need multiple ip in order to host multiple websites on one web server. You need to use "Virtual Hosts" (with https if you need also it). Here there is a guide for virtual hosts on MAMP http://sawmac.com/mamp/virtual/

share|improve this answer
    
To host multiple sites with HTTPS enabled I believe they each need a separate IP address. See: stackoverflow.com/questions/11217538/… –  user1086746 Jun 27 '12 at 16:01
    
@user1086746 Apache supports TLS Server Name Indication, as do all major client browsers on.. pretty much every OS that's not Windows XP. The answer you should have gotten on your linked question is to set NameVirtualHost *:443. –  Shane Madden Jun 28 '12 at 1:01
    
@Shane that still doesn't appear to work when dealing with multiple sites using HTTPS over the same IP address. I did post what ended up working for me. –  user1086746 Jun 28 '12 at 15:12
    
@user1086746 It most certainly works; I'm guessing your NameVirtualHost didn't match your <VirtualHost> blocks, if you were binding specifically to 127.0.0.1. No matter in this case since you've found a working solution, but NoNoNo is right - you don't need extra IPs. –  Shane Madden Jun 28 '12 at 15:30
    
Well, I would like to get this working 'correctly' as setting up those IP addresses are an extra step. I have 2 NameVirtualHosts like: NameVirtualHost *:80 NameVirtualHost *:443 and have tried using vhosts like: <VirtualHost _default_:443> and <VirtualHost 127.0.0.1:443>, but neither will provide an HTTPS connection after the first listed vhost. I could provide the full ssl.conf and vhost.conf files if you were interested! –  user1086746 Jun 28 '12 at 15:43

To alias localhost, you can use this terminal command to create a 'loopback':

ifconfig lo0 alias 127.0.0.2

With the localhost alias setup, you can create multiple HTTPS virtual hosts thusly:

<VirtualHost 127.0.0.1:443> ...... </VirtualHost>
<VirtualHost 127.0.0.2:443> ...... </VirtualHost>

You could also initialize these hosts on startup, if desired, through root's cron:

sudo crontab -e
@reboot ifconfig lo0 alias 127.0.0.2

Hopefully this helps anyone running into the same issues I did!

share|improve this answer
    
Thanks a lot, that's exactly what I was looking for! –  vdboor Jul 3 '13 at 8:25
    
Using echo PASSWORD is a terrible idea. A crude alternative would be to put something in root's cron like sudo crontab -e and @reboot ifconfig lo0 alias 127.0.0.2. There is certainly a more elegant solution, but anything that involves your password in plain text is unacceptable. –  chmac Apr 10 at 11:46

You never need to add additional IP addresses to the local host on any operating system (Unix like, Windows, whatever). They will all respond by default, without additional configuration, to all IP addresses from 127.0.0.0/8:

$ ping 127.254.0.100
PING 127.254.0.100 (127.254.0.100) 56(84) bytes of data.
64 bytes from 127.254.0.100: icmp_seq=1 ttl=64 time=0.026 ms

So just make your application listen on any IP from the 127.0.0.0/8 range and you shall be good to go.

Example:

One console:

$ nc -vvl 127.0.34.2 9022
Connection from 127.0.0.1 port 9022 [tcp/*] accepted
Hello

Another console:

$ echo Hello | nc -vv 127.0.34.1 9022
nc: connect to 127.0.34.1 port 9022 (tcp) failed: Connection refused
$ echo Hello | nc -vv 127.0.34.2 9022
Connection to 127.0.34.2 9022 port [tcp/*] succeeded!
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.