trying to configure my virtual host files on an apache server for local development on a mac - apache

trying to configure a virtual host for my project however the server automatically picks up the root directory. Below is what i have configured it to be.
<VirtualHost 127.0.0.2:8080> ServerName project-1.local DocumentRoot "/Users/mac/Projects/project-1/public" <Directory "/Users/mac/Projects/project-1/public"> AllowOverride All Require all granted </Directory> </VirtualHost>
However this is what i get when i run apachectl -S
VirtualHost configuration: 127.0.0.2:8080 project-1.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:40) ServerRoot: "/usr/local/opt/httpd" Main DocumentRoot: "/usr/local/var/www" Main ErrorLog: "/usr/local/var/log/httpd/error_log" Mutex mpm-accept: using_defaults Mutex default: dir="/usr/local/var/run/httpd/" mechanism=default PidFile: "/usr/local/var/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="_www" id=70 not_used Group: name="_www" id=70 not_used
What am i doing wrong here?
this is what my hosts file looks like
127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.2 project-1.local
i tried changing the vhost file and resaving it however it didnt work

Related

Apache 2.4 installed on windows 11 and unable to get correct browser responses to requests for NamedVirtualHosts

I have Apache Lounge httpd-2.4.54-win64-VS17.zip installed on Windows 11.
I am following instructions at [1] to set up 2 vhosts. The vhosts are defined as:
# Ensure that Apache listens on port 80
#Listen *:80
<VirtualHost 192.168.0.1:80>
#/www/example1 directory is ralative to ${ServerRoot} which is "c:/apache24"
DocumentRoot "C:/Apache24/www/bletch"
ServerName bletch.net
ServerAlias www.bletch.net
</VirtualHost>
<VirtualHost 192.168.0.1:80>
DocumentRoot "C:/Apache24/www/dorfy"
ServerName dorfy.org
ServerAlias www.dorfy.org
</VirtualHost>
In httpd.conf, the Include conf/extra/httpd-vhosts.conf is uncommented.
The contents of /etc/hosts is:
127.0.0.0 localhost
::0 localhost
192.168.0.1 bletch.net
::1 bletch.net
192.168.0.1 dorfy.org
::1 dorfy.org
My httpd.conf contains the following:
Define SRVROOT "C:/Apache24"
ServerRoot "${SRVROOT}"
Listen 80
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Include conf/extra/httpd-vhosts.conf
I have a unique index.html file in the htdocs, bletch, and dorfy directories so I will know exactly which one, if any, is being displayed in browser when requested. And I am using two browsers for testing, google chrome and ms edge.
I have cleared browser cache, set browswer to recognize and use /etc/hosts for local DNS lookup, and have run ipconfig /flushdns, and restarted httpd.
I have executed httpd -t -D DUMP_VHOSTS -D DUMP_RUN_CFG and got the following report:
C:\Apache24\bin>httpd -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
VirtualHost configuration:
192.168.0.1:80 is a NameVirtualHost
default server bletch.net (C:/Apache24/conf/extra/httpd-vhosts.conf:44)
port 80 namevhost bletch.net (C:/Apache24/conf/extra/httpd-vhosts.conf:44)
alias www.bletch.net
port 80 namevhost dorfy.org (C:/Apache24/conf/extra/httpd-vhosts.conf:51)
alias www.dorfy.org
ServerRoot: "C:/Apache24"
Main DocumentRoot: "C:/Apache24/htdocs"
Main ErrorLog: "C:/Apache24/logs/error.log"
Mutex default: dir="C:/Apache24/logs/" mechanism=default
PidFile: "C:/Apache24/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: SRVROOT=C:/Apache24
THE PROBLEM IS:
Request for localhost works correctly in both browers.
Request for www.bletch.net and www.dorfy.org in both browsers reslults in site can't be reached.
Request for bletch.net and dorfy.org both result in display of locoalhost index.html.
I have reviewed multiple posts on StackOverFlow, and Apache users list archive and found solutions to various problems (such as the need to set browsers to use /etc/hosts DNS lookup file and other mistakes I made) but have not found what is needed at the current state explained here.
Please, can anyone tell me what how to fix this? Thanks.
[1] [Troubleshooting Vhosts][1]

virtual host setup shows default apache2 page

I have setup a new virtual host on my ubuntu 16.04 machine but it redirects me to apache's default virtual host (which is disabled).
Below is the contents of the apache virtual hosts config file;
VirtualHost configuration:
*:80 roomba.dev (/etc/apache2/sites-enabled/roomba.dev.conf:2)
*:443 is a NameVirtualHost
default server roomba.dev (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost roomba.dev (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost roomba.dev (/etc/apache2/sites-enabled/roomba.dev.conf:10)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
the domain is https://roomba.dev
You do not really have a question but based on the fact that I too am trying to setup a virtual host if not several, I have found a work around for the official Ubuntu virthost setup tutorial and the associated docs . They just do not work, see these comments and the confusion that ensued. I am assuming the were providing a clean way to add virtualhosts, similar to how you add APT lists in Linux.
Define your new virtual host in the default-ssl.conf file:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
...
</VirtualHost>
</IfModule>
I hope that you did not delete it. After that first virtual host closing tag, add a new host as described in the tutorial instead of creating a new configuration file. For example;
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
...
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin admin#roomba.dev
DocumentRoot /path/to/new/virtualhost
ServerName roomba.dev
ErrorLog ${APACHE_LOG_DIR}/roomba-error.log
CustomLog ${APACHE_LOG_DIR}/roomba-access.log combined
</VirtualHost>
</IfModule>
You can add as many as you want. I am still searching for documentation that could discourage this with explanations. As again, the Apache tutorial does not work but this does, yet they bothered to write it that way, several times. There must be a reason why.
NB: do not touch any permissions. Except the original virtual server directories, based on the http error codes.

Wrong DocumentRoot being used in Apache Docker container

Even though I specified a DocumentRoot in my configuration, I need to specify the sub folder included in the DocumentRoot to load URLs.
Works: 192.168.2.35/default/index.html
Doesn't work, but is wanted: 192.168.2.35/index.html
Output of docker exec -it apache httpd -S showing virtual host loaded:
me#server:/var/www/html$ docker exec -it apache httpd -S
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
192.168.2.35:80 localhost (/usr/local/apache2/conf/enabled-sites/default.conf:10)
ServerRoot: "/usr/local/apache2"
Main DocumentRoot: "/usr/local/apache2/htdocs"
Main ErrorLog: "/proc/self/fd/2"
Mutex default: dir="/usr/local/apache2/logs/" mechanism=default
PidFile: "/usr/local/apache2/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
My volumes for the Docker container:
"Binds": [
"/var/www/html:/usr/local/apache2/htdocs:rw",
"/etc/apache2/conf:/usr/local/apache2/conf:ro",
"/var/log/apache2:/usr/local/apache2/logs:rw"
],
default.conf:
<Directory /usr/local/apache2/htdocs/default>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
<VirtualHost 192.168.2.35:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /usr/local/apache2/htdocs/default
LogLevel debug
ErrorLog logs/error.default.ca.log
CustomLog logs/access.default.ca.log combined
</VirtualHost>
The IP specified for the virtualhost doesn't match the IP used by Docker.
Using *:80 in the virtualhost instead fixes it.

Apache Virtual Host (Ubuntu) redirecting to wrong document root

I'm trying to setup an Apache server with several virtual hosts (www.domain.com & store.domain.com), but for some reason, when I just have one of them enabled (store.domain.com) Apache redirects to the wrong document root (/var/www), which is apparently the default one. This is the virtual host configuration file for the one that's not redirecting correctly:
<VirtualHost *:80>
ServerName store.domain.com
ServerAdmin mail#domain.com
DocumentRoot /var/www/store/public_html/
ErrorLog /var/www/store/logs/error.log
CustomLog /var/www/store/logs/access.log combined
</VirtualHost>
When I run the command apache2ctl -S I get the following:
Name or service not known: AH00547: Could not resolve host name *80 --ignoring!
AH00558: apache2: Could not reliably determine the server's fully qualified domain name,
using xxx.xxx.xxx.xxx. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
....
Looks like the key is on the first line of the previous error, but I can't figure out what's wrong.
When I have the following virtual host enabled, it works fine:
<VirtualHost *:80>
ServerAdmin mail#domain.com
ServerName www.domain.com
DocumentRoot /var/www/html/www/public_html/
ErrorLog /var/www/html/www/logs/error.log
CustomLog /var/www/html/www/logs/access.log combined
</VirtualHost>
When this last virtual host is enabled, store.domain.com redirects to www.domain.com

Why doesn't this Apache virtualhost entry work?

I'm running Apache 2.4.6 on Ubuntu 13.
In sites-available, I have a conf file for my site that contains only this:
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin somebody#somewhere.com
ServerName www.ourco.me
ServerAlias ourco.me
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/ouruser/public/ourco.me/public
# Log file locations
LogLevel warn
ErrorLog /home/ouruser/public/ourco.me/log/error.log
CustomLog /home/ouruser/public/ourco.me/log/access.log combined
</VirtualHost>
There are no other conf files enabled. When I have use apachectl -S to display the sites, it shows:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
alias ourco.me
port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
alias ourco.me
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
The first thing I notice is the duplicate entry for namevhost www.ourco.me. And when I visit the site in a browser, I get:
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at www.ourco.me Port 80
All the directories and files specified in the conf file exist. a2ensite and a2dissite work as expected to add/remove a symlink for this file from sites-enabled, so it's looking at the right file. Does anyone know why its directives are being ignored? Thanks.
Put Allow from all
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin somebody#somewhere.com
ServerName www.ourco.me
ServerAlias ourco.me
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/ouruser/public/ourco.me/public
# Log file locations
LogLevel warn
ErrorLog /home/ouruser/public/ourco.me/log/error.log
CustomLog /home/ouruser/public/ourco.me/log/access.log combined
Allow from all
</VirtualHost>
This appears to solve the problem:
<Directory />
Require all granted
</Directory>
when placed in the VirtualHost entry.
That snippet came from this post. I'm looking at this Apache doc to see why it works.