VirtualHosts Not Working for Locally Hosted Apache Web Server - apache

I have an apache web server setup on my development machine (macos sierra). The configuration I had setup has been working fine for months, but for some reason it decided to stop working today. I have to include the port number (i.e. mysite.local.com:8080) for any locally hosted site I want to navigate to. If I leave off the port number I get ERR_EMPTY_RESPONSE in the browser. The config test is passing with no errors. I haven't upgraded or changed anything on this machine (that I can recall) that would cause virtual hosts to stop working. Can anyone suggest a way to pin down what the issue is here?
FYI
sudo apachectl -S produces
VirtualHost configuration:
*:87 bto.local.tura.com (/private/etc/apache2/sites-enabled/bto.local.tura.com.conf:2)
*:8080 is a NameVirtualHost
default server mr.local.tura.com (/private/etc/apache2/sites-enabled/mr.local.tura.com.conf:1)
port 8080 namevhost mr.local.tura.com (/private/etc/apache2/sites-enabled/mr.local.tura.com.conf:1)
port 8080 namevhost optics.local.tura.com (/private/etc/apache2/sites-enabled/optics.local.tura.com.conf:1)
*:85 overstock.local.tura.com (/private/etc/apache2/sites-enabled/overstock.local.tura.com.conf:1)
*:86 static.local.tura.com (/private/etc/apache2/sites-enabled/static.local.tura.com.conf:1)
My httpd.conf:
Listen 8080
Listen 85
Listen 86
Listen 87
...
ErrorLog "/var/log/apache2/error.log"
...
Include /private/etc/apache2/sites-enabled/*.conf
An example of a vhhost config file:
<VirtualHost *:85>
ServerName overstock.local.tura.com
DocumentRoot /usr/local/web/overstock
ErrorLog /var/log/apache2/overstock.local.tura.com.error.log
CustomLog /var/log/apache2/overstock.local.tura.com.access.log "combined"
<Directory "/usr/local/web/overstock">
Order Deny,Allow
Deny from all
Allow from all
Options -Indexes +FollowSymLinks
</Directory>
LogLevel emerg
</VirtualHost>

I think you should add
Listen 80

try by changing deny from none in place of deny from all

what are errors from /var/log/apache2/error.log ,paste the content of error.log

Related

Apache2 keeps redirecting to default page

I've installed some software for users to be able to change their ldap password on they own named self service password on this path: /usr/share/self-service-password/htdocs.
In sites-enabled my configuration is as follows: (file named 000-default.conf)
<VirtualHost *:80>
ServerName <IP>
DocumentRoot /usr/share/self-service-password/htdocs
DirectoryIndex index.php
AddDefaultCharset UTF-8
LogLevel warn
ErrorLog /var/log/apache2/ssp_error.log
CustomLog /var/log/apache2/ssp_access.log combined
</VirtualHost>
(same thing is "configured" at sites-available").
I've made sure this .conf file (000-default) is enabled by a2ensite, and made sure everything else is disabled, and restarted apache2.
However, When browsing to my IP:81 , it keeps redirecting me to Apache default welcome page under /var/www/html .
I'm trying to find a solution for it for the past 2 hours and couldn't find the reason behind it.
Thanks for anyone willing to assist.
As per your configuration your VirtualHost is accepting connections on port *:80
<VirtualHost *:80>
But then you are testing on IP:81.
Could you please adjust your test to IP:80
or
Adjust the VirtualHost port to *:81
They must match to work.

How to solve issue – Port 8040 the connection has timed out..why?

I want to configure apache to listen on port 8040
I added LISTEN 8040 directive in httpd.conf
Listen 8040
ServerName localhost:8040
and assign this port number to my project in httpd-vhosts.conf
<VirtualHost *:8040>
ServerAdmin "webmaster#dummy-host2.example.com"
DocumentRoot "/opt/lampp/htdocs/project"
ServerName "localhost:8040"
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
and restarted the server.
but it shows this error
The connection has timed out.The site could be temporarily unavailable or too busy.
same process done for port number 80
Listen 80
ServerName localhost:80
it's working fine.
other port numbers not taking why?
what else do I need to configure???? Please help.
If it matters, I use centOS server.
any help is great appreciation.
You should probably allow port 8040 in your firewall.

Connection to localhost fails

I set up /etc/apache2/extra/httpd-vhosts.conf as follows:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
In /Library/WebServer/Documents/ is the standard index.html.en file which was shown perfectly in the browser before I included the httpd-vhosts.conf into my httpd.conf.
The connection to localhost fails using both, Chrome and Firefox. Is the setup correct? What else could go wrong?
I solved the problem. I couldn't state further information because I just didn't know where I could look for the problem. This post put me in the right way:
http://macosx.com/forums/mac-os-x-system-mac-software/299851-apache-wont-start-up.html
sudo apachectl configtest
Gave me an syntax error within the httpd.conf file. After fixing it everything worked. The important thing is the opportunity to run a configtest.

XAMPP apache server not using the ports I desire, not certain why

So, I've been setting up this HTTP server for a school project that has to be able to maintain multiple domains through virtual hosts. Using XAMPP I have my server set up, I thought I'd done it properly but perhaps not.
I had heaps of issues with not being able to listen to a port, to solve this I used (in httpd.conf under apache/conf/)
Listen 0.0.0.0:8080
ServerName localhost:8080
If I used 80/81/8080/321/any combination that did not have the prefix 0.0.0.0 it told me the port could not be listened or whatever (sorry, a little rusty with my syntax).
I set up my first virtual host up like so (under apache/conf/extra/httpd-vhosts.conf):
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "H:/xampp2/xampp/htdocs"
ServerName localhost:8080
<Directory "H:/xampp2/xampp/htdocs">
Option Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I thought this seemed all good and well and I don't believe I've modified anything else. To me, I would expect that this means my Apache server would use port 8080 for the server? However, when I start Apache in XAMPP it states quite clearly
Apache started [Port 80]
Why would this be port 80?
In conjunction, localhost:8080 doesn't navigate me to the documents, but localhost:80 or localhost do. I presume that this just means it's still on port 80. I've tried resetting my computer and XAMPP.
If you need any more information, please let me know. I tried following guides such as this one: http://ailoo.net/2008/07/set-up-multiple-virtual-hosts-on-xampp-for-windows/
Cheers.
Oh, I also edited my Windows HOSTS file; it looks like so:
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost
127.0.0.1 localhost:8080
Edit: New error... Now getting this when I init, doesn't seem to be affecting it though:
ERROR: Status Check Failure [3]
This program must be run from your XAMPP root directory.
It is being run from teh root directory as far as I can tell.
Ok Im not advanced in this area either. However after much playing around with XAMPP and following a few different guides I got mine working.
The Host under drivers seems abit weird. I declared mine as:
127.0.0.1:8080 test.localhost.com
127.0.0.1:8080 test2.localhost.com
Back up you Xampp, then extract a clean install to C: - Just because that Status check failure sounds like bad news.
!Remember to run setup_xampp.bat from the xampp directory and install the apache service!
Then under you httpd.conf add:
ServerRoot C:\xampp\apache
Listen 7070
Listen 8080
Listen 9090
Apache might not like that at first but meh.
The ServerRoot may already be declared above the Listen spot so just double check.
After that head to C:\xampp\apache\conf\extra.
Edit the httpd-vhosts.conf.
Under the section Name-based virtual hosting add:
NameVirtualHost *:7070
NameVirtualHost *:8080
NameVirtualHost *:9090
There will be a couple of examples of virtual hosts below that. Add:
<VirtualHost *:7070>
DocumentRoot "C:/xampp/www/YOURWEBSITEDIR1"
ServerName test.localhost.com
<Directory "C://xampp/www/YOURWEBSITEDIR1">
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:9090>
DocumentRoot "C:/xampp/www/YOURWEBSITEDIR2"
ServerName test2.localhost.com
<Directory "C://xampp/www/YOURWEBSITEDIR2">
Allow from all
</Directory>
</VirtualHost>
Not the double slash in the Directory tag. Now ensure there is an index.html under each of those directories. Restart the apache (Stop, start).
I cant navigate to the test.localhost.com URLs, probably due to the fact they are terribly wrong in the HOSTs config. Though I can connect to 127.0.0.1:7070, 127.0.0.1:9090 and access the webpages from there.
Also 127.0.0.1:8080 connects me to the xampp welcome panel that localhost used to connect you too.
Hope this helps and good luck!
I'm pretty sure that saying 'listening on port 80' is hard-coded into XAMPP, regardless of the port you use. Thus, your code should work fine.
In my .conf file, it just says "listen 80" instead of Listen 0.0.0.0:8080
Cheers.

Having challenges creating virtual servers on apache server for win7 (resolving hostname)

I have an apache server installed on my portable windows 7 machine using xampp as an interface. I've been working with a few people on an irc channel but must soon go to bed and replies are getting slower.
I have the following code added to my httpd.conf file:
#virtual servers
#Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost.MEALS
DocumentRoot C:\xampp\htdocs\MEALS
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.HA
DocumentRoot C:\xampp\htdocs\Hackers
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.WIK
DocumentRoot C:\xampp\htdocs\WhoIKnow
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.TUS
DocumentRoot C:\xampp\htdocs\Unity
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.PHP
DocumentRoot C:\xampp\htdocs\phpMyAdmin
DirectoryIndex index.php
</VirtualHost>
And I have the following configuration:
Setting environment for using XAMPP for Windows.
John#ASSIMILATER C:\xampp
# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:80)
*:80 is a NameVirtualHost
default server localhost.MEALS (C:/xampp/apache/to which there was conf/httpd.conf:512)
port 80 namevhost localhost.MEALS (C:/xampp/apache/conf/httpd.conf:512)
port 80 namevhost localhost.HA (C:/xampp/apache/conf/httpd.conf:516)
port 80 namevhost localhost.WIK (C:/xampp/apache/conf/httpd.conf:520)
port 80 namevhost localhost.TUS (C:/xampp/apache/conf/httpd.conf:524)
port 80 namevhost localhost.PHP (C:/xampp/apache/conf/httpd.conf:528)
Syntax OK
John#ASSIMILATER C:\xampp
#
However when I try to access localhost.PHP in my web browser it tells me the server is not found. I was instructed that I need to resolve the host names on my machine. I was directed to a few irc channels (dns and windows) to which there was no reply. I searched google and ran across this site: http://technet.microsoft.com/en-us/library/bb727005.aspx#EEAA. I'm not quite sure what I'm reading and as near as I can tell it doesn't quite give me a clear instruction on where to resolve the host name or a file to edit.
Also currently the default server is the top virtual server in the code. I would like to call localhost and show a simple html page I created which is in "htdocs/index.html" which will navigate to the other servers (links pointing to "localhost.PHP" etc). is there a way to have the default server remain "localhost" which points to "htdocs/index.html" while maintaining the other virtual servers, or will I have to create another virtual server and make that the default?
Any and all help appreciated.
edit: I had someone help me find the HOSTS file on my machine but am unable to edit it. I turned off all antivirus features, turned off spybot (UAC was always off and I always run with administrator privileges) specifically right clicked on np++ editpadlite and windows notepad and was only able to edit in notepad, but was required to save the file with a different name.
You have to explicitly run Notepad as an administrator (regardless of UAC settings) and when you go to save, make sure you select 'all files' rather than the default *.txt.
I found the same thing when I tried to edit the hosts file on W7, but it seems that just being an administrator on the machine isn't quite the same as explicitly running the program as an administrator.