Apache virtualHost ignored or pointing to the default one
I'm trying to setup my Apache on OSX, but I'm not able to make my local url 'awr.local' point to the correct path. I mean whether I type http://localhost or http://awr.local, it always shows me the index.html page in my 'localhost' vhost path. I've restarted my httpd service countless times, with or without sudo.
Any help would be greatly appreciated, thanks :'|
I've been following a tutorial (https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions), here are the steps about Apache :
Disabling the bundled Apache and installing the one from homebrew :
sudo apachectl stop sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null brew install httpd
Then, some httpd.conf modifications :
# changed Listen 8080 to : Listen 80 [...] # changed DocumentRoot "/usr/local/var/www" to : DocumentRoot "/Users/wallace/dev/default" [...] # changed <Directory "/usr/local/var/www"> to : <Directory "/Users/wallace/dev/default"> [...] # changed AllowOverride None to : AllowOverride All # uncommented : LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so [...] # changed # User _www # Group _www # to : User wallace Group staff [...] # added the missing line : ServerName localhost
Until this point everything seemed to be working fine, I've installed PHP and MariaDB without any problem.
Then came the virtual hosts part :
Some other httpd.conf modifications :
# uncommenting these lines LoadModule vhost_alias_module lib/httpd/modules/mod_vhost_alias.so [...] Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
Editing the file /usr/local/etc/httpd/extra/httpd-vhosts.conf :
<VirtualHost *:80> DocumentRoot "/Users/wallace/dev/default" ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "/Users/wallace/dev/awr" ServerName awr.local </VirtualHost>
The /etc/hosts file :
127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.1 awr.local ::1 awr.local
The output of 'httpd -S' :
VirtualHost configuration: *:80 is a NameVirtualHost default server localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:25) port 80 namevhost localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:25) port 80 namevhost awr.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:30) ServerRoot: "/usr/local/opt/httpd" Main DocumentRoot: "/Users/wallace/dev/default" Main ErrorLog: "/usr/local/var/log/httpd/error_log" Mutex rewrite-map: using_defaults Mutex default: dir="/usr/local/var/run/httpd/" mechanism=default Mutex mpm-accept: using_defaults PidFile: "/usr/local/var/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="wallace" id=501 not_used Group: name="staff" id=20 not_used
Well, today when I was preparing to try the answer of Juan, I had something new : instead of serving me the localhost, the awr.local url showed me a 403 forbidden. After a new research & doc reading, I managed to make it work like this :
My /usr/local/etc/httpd/extra/httpd-vhosts.conf file :
The Require all granted is the most important part.
<VirtualHost *:80> DocumentRoot "/Users/wallace/dev/default" ServerName localhost <Directory "/Users/wallace/dev/default"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot "/Users/wallace/dev/awr" ServerName awr.local <Directory "/Users/wallace/dev/awr"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
I had to restart Apache with sudo for it to work :
sudo brew services stop httpd && sudo brew services start httpd
Name Based Virtual Hosts, The default virtual host when using name based virtual hosts is the In one config file: NameVirtualHost *:80 # In another config file: NameVirtualHost *:80 Apache will ignore the second directive and use the first defined� This may be obvious, but don't forget to restart the apache service after enabling additional virtual host. After executing a2ensite for the second virtual host, the output of apache2ctl -S reflects that both sites are configured (and one of them is the default), but it won't be live until you reload apache.
This is how I have it setup (I've made changes to match your configuration). Besides awr.local must be in your /etc/hosts file pointing to 127.0.0.1 or any other network interface you want to use.
<VirtualHost awr.local:80> DocumentRoot "/Users/wallace/dev/awr" ServerName awr.local <Directory "/Users/wallace/dev/awr"> AllowOverride All Order allow,deny allow from all Require all granted </Directory> </VirtualHost>
An In-Depth Discussion of Virtual Host Matching, Each VirtualHost directive includes one or more addresses and optional ports. at startup and if any name resolutions fail, those virtual host definitions are ignored. If the main server has no ServerName at this point, then the hostname of the For any undefined ServerName fields, a name-based vhost defaults to the� I'm running a LAMP server on Fedora 13 that's working fine; however, I just added an ".htaccess" file to my current site's docroot folder that is being completely ignored. I've tried half a dozen different tests, including this one: RewriteEngine on RewriteBase / RewriteRule ^.*$ index.php
I had the same problem and couldn't get it to work no matter what I tried. Stopping, starting or restarting httpd did not work. Even though httpd -S always reported the correct settings, all browsers loaded the default docroot, regardless of the virtualhost settings. Then I noticed something strange. After stopping httpd with
brew services stop httpd I reloaded localhost in the browser and it still loaded without a problem. This gave me the idea to
sudo killall httpd then start it again with
brew services start httpd. After this, all was fine.
Why Is Apache Ignoring Some Of My Virtual Hosts? :: Sparrowtail, Last night I learned an interesting lesson about Apache virtual host directives. myhost (/etc/apache2/sites-enabled/000-default.conf:1) port 80 namevhost I knew that public DNS was pointing both the required hostnames� Catching every request to any unspecified IP address and port, i.e., an address/port combination that is not used for any other virtual host. <VirtualHost _default_:*> DocumentRoot "/www/default" </VirtualHost> Using such a default vhost with a wildcard port effectively prevents any request going to the main server.
Virtual hosts not working. Getting a redirect to the default apache page., But, when i type the domain in to the browser, i see the default page at /var/www/ html. which points to the revistaestiloof.com.br domain but with the wrong One thing to keep in mind is that /etc/apache2/sites-available/. Every time I've had trouble in the past with Apache configurations, and especially virtual hosts, I've pulled out the trusty `apachectl -S` command to see what Apache thinks my configuration means. And this made some pretty interesting reading - this server is 18.104.22.168:
Apache isn't respecting the ServerName directive for a particular site , added a line to /etc/hosts pointing domain.com to the server's external IP address. When you have a <VirtualHost> container without a ServerName component, As 000-default probably doesn't have a ServerName component, and is the apache decided was the same as my vhost (defined later), so the default one� Apache comes with a default virtual host file called 000-default.conf that we can use as a jumping off point. We are going to copy it over to create a virtual host file for each of our domains. We will start with one domain, configure it, copy it for our second domain, and then make the few further adjustments needed.
However, since virtual hosts are designed to simulate have multiple separate physical HTTP servers, the silent ignore approach does not seem unreasonable to me. It would be the same as IP-based virtual hosting and firewalling off some of the IPs (perhaps not for all clients).