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.
Related
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
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]
I can't configure two domains with VirtualHost, because, always show me only one domain. I mean, if I visit domainB.com that redirect me to domainA.com and domainA.com works fine. I made this procedure in anothers hosts like: DigitalOcean or my own localhost, but with this instance I can't find the issue. If I disable one site the other works without problem.
I have a google instance with Ubuntu 17.10 and Apache2 with two domains (virtualhost). I disabled the default virtualhost. My folder structure is /var/www/domainA/ and /var/www/domainB/
Cloud DNS is configured with two zones domainA.com and domainB.com with A and CNAME records point to my server IP. I have too NS records pointed to googledomains.com and in my registar I added those DNS.
If I do a ping to both domains, them resolve correctly to my IP address without problem.
I have the two domains configured in sites-available:
#in /etc/apache/sites-available/domainA.com.conf
<VirtualHost *:443>
ServerAdmin webmaster#domainA.com
ServerName domainA.com
ServerAlias www.domainA.com
DocumentRoot /var/www/domainA
ErrorLog ${APACHE_LOG_DIR}/error-domainA.log
CustomLog ${APACHE_LOG_DIR}/access-domainA.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/sslcert/certified-number.crt
SSLCertificateKeyFile /etc/apache2/sslcert/domainA.com.key
SSLCertificateChainFile /etc/apache2/sslcert/gd_bundle-g2-g1.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /var/www/domainA/>
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
#in /etc/apache/sites-available/domainB.com.conf
<VirtualHost *:80>
ServerAdmin webmaster#domainB.com
ServerName domainB.com
ServerAlias www.domainB.com
DocumentRoot /var/www/domainB
ErrorLog ${APACHE_LOG_DIR}/error-domainB.log
CustomLog ${APACHE_LOG_DIR}/access-domainB.log combined
<Directory /var/www/domainB/>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
Result of apachectl -S command:
sudo apache2ctl -S
VirtualHost configuration:
*:80 domainB.com (/etc/apache2/sites-enabled/domainB.conf:1)
*:443 domainA.com (/etc/apache2/sites-enabled/domainA.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: 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
What other setting I must to check?
UPDATE INFORMATION: If I try with www for the domainA, works fine.
www.domainA.com -> Works
domainA.com -> Doesn't work, redirect to domainB.com
www.domainB.com -> Works
domainB.com -> Works
I had only a VirtualHost configuration in the port 443 for domainA.com.
I added a configuration *:80 with a redirection to ssl and works. Like this:
<VirtualHost *:80>
ServerAdmin webmaster#domainA.com
ServerName domainA.com
ServerAlias www.domainA.com
Redirect / https://www.domainA.com/
</VirtualHost>
Thanks Matt Raines for his comment.
I have deployed my project on linode and configured everything correctly but I find the homepage the only thing to be working. Anything else is giving me The requested url can not be found on this server. I have check all my configurations and everything seems to be correct. a2enmod rewrite is enabled and this 000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteBase /var/www/application
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
What else is missing?
Edit:
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: ENABLE_USR_LIB_CGI_BIN
User: name="www-data" id=33
Group: name="www-data" id=33
You need to set document root to the public folder of your application like so:
"var/www/your-site.com/public"
Try follow my config:
<VirtualHost *:80>
ServerName yourproject.com
ServerAlias www.yourproject.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/yourproject/public
<Directory "/var/www/yourproject/public">
Require all granted
Allowoverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Turns out the .htaccess was missing so that was the reason. I have added it and it is working normally.
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.