Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.
<VirtualHost *:80>
  DocumentRoot "D:/Projects"
  ServerName 192.168.11.74
</VirtualHost>

Why doesn't this work ? How to access websites on the local box (Windows, Apache, MySql, PHP) which are based on IP address assigned by company's internal network which is not accessible to outside. When the laptop gets connected to internal network, all websites works, but when outside of the company network, these IP based url doesn't work even if all the code-base, development environment resides in the local Apache server on the laptop itself.

Is there a way to point 192.168.XX.XXX to 127.0.0.1

share|improve this question
1  
The long-term solution is Mobile IPv6; with this your laptop will always have the same IPv6 address everywhere you go. If you already have IPv6 at your company, you should see if your IT department can set this up. –  Michael Hampton Feb 23 at 14:02
    
I am not sure about this IPv6 at present in the company. I will definitely ask, but is there any other way without changing anything at the company level or permanent change to do this. I am looking for a solution that can be applied on the laptop and when get into the company network it should work as it works usually. I was reading this.. Apache IP-based Virtual Host but not sure if it is the right way. Doesn't work either. –  Subharanjan Feb 23 at 18:38
    
@MichaelHampton s/long-term/very-long-term-not-gonna-happen-real-soon/ –  quadruplebucky Feb 28 at 16:37
    
@quadruplebucky It will be soon enough. If you really want to talk about it, though, comments aren't ideal; try chat. –  Michael Hampton Feb 28 at 16:40
    
Did you bother trying Option 2 in my answer as this is the way it should be really done. You need to use VirtualHosts and DNS. This way you can also simulate different environments. –  edvinas.me Mar 1 at 14:18

6 Answers 6

Option 1

Set ServerName to localhost like this:

ServerName localhost

Then access the server via

http://localhost

It will not matter what IP you have.

Option 2

First you setup VirtualHost like this:

<VirtualHost *:80>
  DocumentRoot "D:/Projects"
  ServerName projecthost
</VirtualHost>

Then on windows you can always set an IP to which "projecthost" will point to. Edit C:\Windows\system32\drivers\etc\hosts file and add:

projecthost 127.0.0.1

or

projecthost 192.168.11.74

Then access the server via

http://projecthost
share|improve this answer
    
It doesn't work. Also, when the IP(192.168.11.74) is being typed in the browser, it should not change the URL rather, it should point to local Apace server which is accessed by 127.0.0.1 or localhost –  Subharanjan Mar 5 at 10:53

If you only intend to use one virtualhost you can use the apache default virtualhost. See: Apache Default Virtual Host

If you're hosting multiple virtualhosts edvinas provides the answer. Create a name for each project, and create a entry on your hosts file with that name pointing to 127.0.0.1 which is always available.

share|improve this answer
    
So we cant have IP based ServerName in the virtual host configuration in Apache ? Like this: <VirtualHost *:80> DocumentRoot "D:/Projects" ServerName 192.168.11.74 </VirtualHost> So any request made on that laptop with specific IP based url will point to the local Apache where the project has been setup ? Let me read the Apache Default Virtual Host. Thanks !! –  Subharanjan Feb 28 at 12:49
    
You can think of the ServerName as what you type at the browser URL and get redirected to that website. If you type 192.168.11.74 and the servername is 192.168.11.74 then you get to the right place, as long as 192.168.11.74 works (happens on your office network) but doesn't when it doesn't resolve. 127.0.0.1 always resolves to your local computer so you can use that one and access the site as 127.0.0.1, but other people won't be able to access it. That's the reason why default virtualhost is probably the best solution, but it all depends on what your requirements are. –  Manuel Sousa Feb 28 at 13:01

This doesn't work because the 'ServerName' parameter to Apache says effectively: If you get a request, make sure that the URL specified by the user has 192.168.11.74 as the destination. When you are outside of your company network and not using that IP address (because you were assigned another), then your request will either:

  • Reach the Apache server but have a different IP address (either 127.0.0.1 or whatever IP you were assigned by the foreign network), or
  • Not reach the Apache server because your computer doesn't know where 192.168.11.74 is anymore (it has forgotten its former identity because it is irrelevant to its new network location)

If you only need the one web site (likely at this stage), I would recommend removing the ServerName line because it doesn't help you (as recommended by Manuel Sousa) and using 127.0.0.1 locally, and 192.168.11.74 when you are on your work network.


An example of a sub-optimal approach that might achieve the stated goal, you can try to configure your network card to have an additional IP address (192.168.11.74) while you are not at work. Challenges:

  • This might not work if your external network has a dynamic IP address.
  • This will likely interfere with your computer functioning on your work network.

Again, I think this approach is a bad idea, but you can judge for yourself: http://social.technet.microsoft.com/Forums/windows/en-US/691d5aa4-09a3-4390-856a-26c10d773a3b/how-to-assign-differentmultiple-ip-address-to-nic-network-card?forum=w7itpronetworking

share|improve this answer

Do you have anything else (another Virtual Server, Perhaps) that Listens in 127.0.0.1 ??

If not, you can very well edit the vhost to resolve for all traffic receiving in 127.0.0.1

share|improve this answer
    
the internal ip address(192.168.11.74), 127.0.0.1, localhost: all points to the same one project directory under which I keep all projects as separate directories. Can you pls provide me what should be the content into the vhost file. –  Subharanjan Feb 23 at 18:50

What if you try a batch file that changes the host file (C:\Windows\system32\drivers\etc\hosts ) when you are outside the network and then another one when you are inside?

Have it set up so that when you are outside the corporate network, it adds this line:

192.168.11.74    127.0.0.1

And then another one to comment it out once you get into the corporate network like this:

#192.168.11.74    127.0.0.1

Or just simply removing the line should also work.

This way, can keep the apache config intact and just make changes on your laptop.

Cheers!

share|improve this answer
    
It doesn't work. Also, I don't think we can point one IP to another in this manner in the hosts file. –  Subharanjan Mar 5 at 10:57

You can work around this with a dynamic DNS service that lets you use private address space. (I know dyn.com does, for example, but I have no opinion one way or the other on their services)

For example you'd use:

ServerName myapp-whatever.dyndns.org

in your apache conf and run an update client that supports using your interface address (not your detected public IP, which is what most do, but will break for you)

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.