I’m using Apache 2.4 on Mac. I want to set up a virtual host to serve up my Javascript-based (React) application. I have created this virtual host configuration …
<VirtualHost *:80>
ServerName maps.example.com
Alias / /Library/WebServer/Documents/client
<Directory /Library/WebServer/Documents/client>
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
</VirtualHost>
However, when I visit my local server, http://maps.example.com/ , I just see a listing of my directory …
I would like my browser to actually be served and attempt to reference my files. Interestingly, when I visit
http://maps.example.com/index.html
I get a 404.
Edit: Here is my Apache config file, /etc/apache2/httpd.conf. Note the include at the end.
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^.([Hh][Tt]|[Dd][Ss]_[Ss])">
Require all denied
</FilesMatch>
...
Include /private/etc/apache2/other/*.conf
The original include I posted is in /etc/apache2/other/maps.conf
2
Answers
I just used apache 2.4 on my mac and I set up a virtual host and served a simple react app Successfully.
I checked my config and compared with yours and also tried to copy most of your config and run it on my mac etc. Here are some suggestions and the config code I used. Just review and see if it helps.
Suggestions:
<Directory /Library/WebServer/Documents/client>
in<VirtualHost *:80>
section and<Directory "/Library/WebServer/Documents">
in the main. See if info is any useful in debugging.# Options Indexes FollowSymLinks
and usedOptions All
. See if it helps.apachectl -t
to check syntax before restarting server. Also keep an eye on/var/log/apache2/error_log
My /etc/apache2/httpd.conf:
Have a bit of a play and come back with more info/error-logs if things are not working.
You have no an index.html file in root directory.
You should create it.