0

I have a problem that only takes place in Google Chrome and it is OK in Firefox and IE. I have googled a lot of websites and done a few tips but nothing worked.

I have WAMP Server installed. I have setup two virtual hosts:

The problem is that whenever I enter localhost in the addressbar, It immediately redirects to enginter.local ! And Chrome shows this error for all of local URLs:

This page isn’t working

enginter.local didn’t send any data.

ERR_EMPTY_RESPONSE

httpd-vhosts.conf:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot "d:/wamp/www/real/yegane"
    ServerName yegane.local
    ServerAlias www.yegane.local
    ErrorLog "logs/yegane.local-error.log"
    CustomLog "logs/yegane.local-access.log" common
    <Directory "/">
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot "d:/wamp/www/real/enginter"
    ServerName enginter.local
    ServerAlias www.enginter.local
    ErrorLog "logs/enginter.local-error.log"
    CustomLog "logs/enginter.local-access.log" common
    <Directory "/">
        Require all granted
    </Directory>
</VirtualHost>

And this is my hosts file (in Windows 10):

127.0.0.1       localhost
#::1            localhost

127.0.0.1   enginter.local
127.0.0.1   yegane.local

I tried clearing the DNS cache here chrome://net-internals/#dns And also tried resetting everything to default in chrome://flags but no luck!

Once I restarted the system and the problem was gone. but after a while it happened again. And also port 80 is used by Apache.

I'm sorry if it's confusing. I'm confused myself and it has taken my time for a whole week.

UPDATE

Now all of my browsers are doing this!

UPDATE 2

httpd -S gives:

VirtualHost configuration:
127.0.0.1:*            is a NameVirtualHost
         default server enginter.local (D:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf:43)
         port * namevhost enginter.local (D:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf:43)
                 alias www.enginter.local
         port * namevhost yegane.local (D:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf:57)
                 alias www.yegane.local
*:80                   localhost (D:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf:30)
ServerRoot: "D:/wamp/bin/apache/apache2.4.23"
Main DocumentRoot: "D:/wamp/www"
Main ErrorLog: "D:/wamp/logs/apache_error.log"
Mutex default: dir="D:/wamp/bin/apache/apache2.4.23/logs/" mechanism=default
PidFile: "D:/wamp/bin/apache/apache2.4.23/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: APACHE24=Apache2.4
Define: VERSION_APACHE=2.4.23
Define: INSTALL_DIR=D:/wamp
Define: APACHE_DIR=D:/wamp/bin/apache/apache2.4.23
  • 1
    Your ServerAlias entries do not match the hosts entries. One has www the other doesn't. – DavidPostill Nov 26 '17 at 17:32
  • @DavidPostill Thanks. Now I commented the ServerAlias entries and added a new virtual host with ServerName of localhost (pointing to www directory). Now What happens is this: Contents of yegane,local and enginter,local are shown but the request for localhost redirects (instantly) to enginter.local – pooria Nov 27 '17 at 8:45
  • 1
    shrug I told you what was wrong and you appear to have made some other change ... – DavidPostill Nov 27 '17 at 20:28
  • Any "localhost" virtual host should be first (before either of the other host entries). ServerAlias for your second and third hosts should appear exactly as listed in your original question example (i.e. www.example.local and uncommented). – Anaksunaman Nov 28 '17 at 6:19
  • @DavidPostill Sorry I though that you're saying ServerAlias makes that change mandatory so I commented it. Now I did as you said and added www.*.local (* for each virtual host) But nothing changed. Again, localhost redirects to enginter.local – pooria Nov 28 '17 at 6:41
0

I would structure your virtual host entries in httpd-vhosts.conf as follows:

# Assuming we wish to type in e.g. "localhost" in Chrome

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName localhost
    #ServerAlias should be unneeded 
    DocumentRoot "d:/wamp/www/real/localhost"  # Or whatever directory is appropriated
    ErrorLog "logs/localhost.local-error.log"
    CustomLog "logs/locahost.local-access.log" common
    #... Other stuff ...
</VirtualHost>

#... Other entries as listed ...

Note that #... Other stuff ... can obviously be Directory information or anything else you wish to include but is not required. This configuration should give you access to "localhost" in your browser by either typing "localhost" or "127.0.0.1".

There is are ServerName and DocumentRoot entries for localhost in the main httpd.conf file, too[.]

You shouldn't need to change anything about the DocumentRoot in httpd.conf but you should change the ServerName entry in httpd.conf, specifically to something other than "localhost" (e.g. ServerName MyCoolServer =P).

You will (of course) want to restart your WAMP (Apache) server and flush your browser cache (you may even want to do it twice). In Chrome you can use chrome://settings/clearBrowserData. Similar results in Firefox can be achieved with the *History - > Clear History... * options (clear at least the Browsing & Download History and Cache settings from the earliest time possible from the drop down).

  • Thanks man. Now chrome is OK and Firefox has that problem -_- . I flushed the DNS several times. I've done many changes to httpd-vhosts.conf and still the problem exists!! – pooria Nov 28 '17 at 10:30
  • Well, that's unfortunate. It worked fine with Firefox in my tests, so perhaps it is browser caching. I would use the same setup as above and but use History -> Clear Recent History in Firefox. I would select at least the "Browsing..", "Cookies" & "Cache" entries and make sure the time drop down was set to "From The Beginning Of Time" (or whatever the earliest selection is). – Anaksunaman Nov 28 '17 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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