WAMP Virtual Host not working

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I am using a wamp version 2.5 My Apache is 2.4.9 PHP: 5.5.12 MySQL: 5.6.17

I have these configurations:

On my httpd.conf

# Virtual hosts Include conf/extra/httpd-vhosts.conf 

On my G:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhost.conf

# Virtual Hosts # # Required modules: mod_log_config  # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at  #  # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. #   # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any  block. #        ServerAdmin webmaster@dummy-host.example.com     DocumentRoot "g:/Apache24/docs/dummy-host.example.com"     ServerName dummy-host.example.com     ServerAlias www.dummy-host.example.com     ErrorLog "logs/dummy-host.example.com-error.log"     CustomLog "logs/dummy-host.example.com-access.log" common      ServerAdmin webmaster@dummy-host2.example.com     DocumentRoot "g:/Apache24/docs/dummy-host2.example.com"     ServerName dummy-host2.example.com     ErrorLog "logs/dummy-host2.example.com-error.log"     CustomLog "logs/dummy-host2.example.com-access.log" common      ServerAdmin webmaster@dummy-host.example.com     DocumentRoot "g:/wamp/www"     ServerName localhost     ErrorLog "logs/localhost-error.log"     CustomLog "logs/localhost-access.log" common      DocumentRoot "g:\wamp\www\mysite\public"     ServerName mysite.dev 

On my c:\Windows\System32\Drivers\etc\hosts

# localhost name resolution is handled within DNS itself. 127.0.0.1   localhost 127.0.0.1   mysite.dev #   ::1     localhost 

I try to access my project using this URL: http://www.mysite.dev/ BUT I am getting a Server not found error I tried accessing it using www.mysite.dev , http://mysite.dev but still having a bad luck!

My virtual host was working before but i'm not sure why it wasn't working now. Some weird stuff going on.

I am not sure what's happening. Any ideas will be greatly appreciated!

Thanks!

回答1:

First you need to remove the example dummy definitions from your vhost-httpd.conf file. They are there as examples only just to get you started with the syntax, and should not remain in an active conf/extra/httpd-vhosts.conf as they are pointing to non existant folders.

So remove these 2 definitions from the file:

     ServerAdmin webmaster@dummy-host.example.com     DocumentRoot "g:/Apache24/docs/dummy-host.example.com"     ServerName dummy-host.example.com     ServerAlias www.dummy-host.example.com     ErrorLog "logs/dummy-host.example.com-error.log"     CustomLog "logs/dummy-host.example.com-access.log" common      ServerAdmin webmaster@dummy-host2.example.com     DocumentRoot "g:/Apache24/docs/dummy-host2.example.com"     ServerName dummy-host2.example.com     ErrorLog "logs/dummy-host2.example.com-error.log"     CustomLog "logs/dummy-host2.example.com-access.log" common 

Second Apache 2.4.x is IPV4 ( 127.0.0.1 ) and IPV6 (::1) aware so your hosts file should look like this with definitions for both IPV4 and IPV6 versions for each site. The browser can arbitrarily use either so you need both but will probably use the IPV6 network in preference to the IPV4 if both are actually active on your PC.

127.0.0.1   localhost ::1  localhost  127.0.0.1   mysite.dev ::1  mysite.dev 

Now on the 2 Virtual Hosts that actually exist on your system try this as the Virtual Host definition :

     DocumentRoot "g:/wamp/www"     ServerName localhost     ServerAlias localhost     ErrorLog "logs/localhost-error.log"     CustomLog "logs/localhost-access.log" common              AllowOverride All         Options Indexes FollowSymLinks         Require local          DocumentRoot "g:\wamp\www\mysite\public"     ServerName mysite.dev     ServerAlias www.mysite.dev     ErrorLog "logs/mysite-error.log"     CustomLog "logs/mysite-access.log" common              AllowOverride All         Options Indexes FollowSymLinks         Require local     

The .... section within the .... section tells Apache which IP Addresses it is allowed to accept connections from, so using the Apache 2.4 syntax Require local limits access so that only the PC running WAMPServer i.e. Apache can connect to any of these site.

Avoid mixing Apache 2.2 syntax and Apache 2.4 syntax together in the same definition. So dont use

Order Allow,Deny Allow from all 

and

Require all granted 

in the same definition. You are using Apache 2.4 so use the Apache 2.4 syntax.

If you find you want to allow other PC's inside your local network to see you site i.e. work mate or the kids etc, you can add this syntax to one or more of your Virtual Host definition.

Allow just a single other PC into your site

Require local Require ip 192.168.1.100 

or 2 other PC's

Require local Require ip 192.168.1.100, 192.168.1.101 

Or to anyone on your local network just use the first 3 of the 4 quartiles of the ip address.

Require ip 192.168.1 

Also avoid using the syntax that allows access from anywhere i.e.

Require all granted  

It may solve your issues in the short term, but is just waiting to catch you sometime later when you decide you want to show your site to a friend/client/boss. If you get to the stage of Port Forwarding you router so that the world is allowed into your network that would cause ALL OF YOUR SITES to become available to the world.

Better to change the ONE Virtual Host Definition for the ONE site you want people to see for testing/bragging from Require local to Require all granted and only allow that single site to be access from the internet.

Once you have made all these changes remember to restart Apache.

Also if you change the hosts file to make the chnages active you should either reboot or run these command from the command line of a command windows started ising the Runs as Administrator option.

net stop dnscache net start dnscache 


回答2:

Due to Google acquiring .dev gTLD, having .dev development sites is no longer easily possible, best way to mitigate is to just rename your development domain into .local or something that you prefer.

What happens in the background is that the local DNS server redirects the browser to 127.0.53.53 (open cmd > nslookup yourdomain.dev) in order to inform end-users of .dev gTLD being acquired. Since the .dev domain in hosts file is set to 127.0.0.1 it shows connection refused.

You can change 127.0.0.1 to 127.0.53.53 in the hosts file and see that the browser error changes from ERR_CONNECTION_REFUSED to ERR_ICANN_NAME_COLLISION.



回答3:

Following is working for me

     DocumentRoot "G:\project\test.dev"     ServerAdmin test@gmail.com     ServerName test.dev     ErrorLog "logs/test.dev-error.log"     CustomLog "logs/test.dev-access.log" common             AllowOverride All        Options Indexes FollowSymLinks        Require local     


回答4:

I fix the same problem by uncomment some lines in httpd.conf in Apache folder.

Uncomment lines below:

Include conf/extra/httpd-vhosts.conf LoadModule vhost_alias_module modules/mod_vhost_alias.so 

Save file and Restart your Apache and it will work. Many thanks to this guy: https://john-dugan.com/wamp-vhost-setup/



回答5:

Check out this modules uncommented in httpd.conf

  • proxy_module
  • proxy_http_module


回答6:

try this on you apache httpd.config file:

           ServerName mysite.dev       DocumentRoot "g:\wamp\www\mysite\public"      SetEnv APPLICATION_ENV "development"                DirectoryIndex index.php         Options All Includes Indexes         Options All Indexes FollowSymLinks          Order allow,deny         Allow from all         Require all granted      

restart your wamp server and put url like mysite.dev/ on you browser. hope it will help you. thank you.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!