Wamp in network with a domain name

2019-06-24 05:19发布

问题:

I have configured a Wamp server in my local network and it works great. I can access each project with xxx.xxx.xxx/myproject, but, as another option, can I configure them to access like www.myproject.com or http://myproject.com from the local network? I am an embedded system programmer and I have to access my embedded Ethernet boards with various machines. It works fine with an IP address, but I just want to know if it is possible.

回答1:

you can do that by configuring your virtual hosts and the httpd.conf file of your apache

configure apache

the file of your apache will be located in:

  • c:\wamp\Apache2\conf\httpd.conf

search for something like:

DocumentRoot 'c:/wamp/www'

and add the following code after the DocumentRoot 'c:/wamp/www' into the file:

NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
    ServerName localhost
    DocumentRoot 'C:\wamp\www'
</VirtualHost>
<VirtualHost 127.0.0.1>
    ServerName yourdomain.com
    DocumentRoot 'C:\wamp\www\ClientsMyClient'
</VirtualHost>

configure hostfile

on mac via terminal:

  • sudo nano /etc/hosts

on windows 7:

  • open a texteditor as administrator
  • open file and go to: %Systemroot%\System32\Drivers\Etc

(source: edit hosts file in windows 7)

when you have it opened just write a new line into the file:

XXX.XXX.XXX yourdomain.com
(mostly this will be: 127.0.0.1 yourdomain.com)

I do suggest you use yourdomain.local, because if you ever host a website, you might get confused about which one is the public one and which one is the local website :).

in your browser you then type: yourdomain.com and you should be able to have a project hosted on a wamp server, with his own domain.

hope this helps! :-)

(source: http://viralpatel.net/blogs/how-to-setup-multiple-virtual-hosts-in-wamp/)



回答2:

Open C:\Windows\system32\drivers\etc\hosts and after that localhost address(127.0.0.1) add the domain name which you want like www.example.com and make a space between ip address and domain name.

For Example, 127.0.0.1 www.example.com

Note: You need to open 'hosts' file in Administrator Privileges .