apache2 vhost doesn't always respond - apache2

I added the following virtualhost (i have the default *:80 one of course) to my apache:
Listen 8989
NameVirtualHost 10.8.0.1:8989
<VirtualHost 10.8.0.1:8989>
DocumentRoot /var/crib
ServerName Thor
ServerAlias Thor
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/crib/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from 10.8.0.0/255.255.255.0 ::1/128
</Directory>
</VirtualHost>
But sometimes it doesn't always respond... so I'm wondering what could be the problem?
I don't even know where to look... 10.8.0.1 is my VPN address. The virtual host 80 works perfectly and am wondering if my configuration has any flaws

Are you planning on having >1 virtual host (diff. hostnames) on that same IP and port? if not, remove the NameVirtualHost option and ServerName and ServerAlias. If you are going to do name based hosting, leave all of that, but use a name that resolves in DNS. You can just put something in /etc/hosts on the local system for testing, but eventually you'll have to get a real hostname for other people to access your site/application.

Related

VirtualHost on Apache2 gives no response

I'm trying to create a virtual host on apache2 but I am getting no response. I have tried serveral tutorials but nothing has helped. This is my file:
<VirtualHost *:80>
ServerName androidwebservice.com
DocumentRoot "/var/www/my_webservice/public"
LogLevel warn
ErrorLog /var/log/apache2/redmine_error.log
CustomLog /var/www/my_webservice/android_access.log combined
<Directory "/var/www/my_webservice/">
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
RailsEnv production
RailsBaseURI /my_webservice
PassengerResolveSymlinksInDocumentRoot on
</Directory>
</VirtualHost>
I have enabled it using the command sudo a2ensite androidbackend(this is the file name). The file is located in /etc/apache2/sites-available.
The ServerName has been declared in /etc/hosts:
127.0.1.1 androidwebservice.com
Are you visiting androidwebservice.com or www.androidwebservice.com
Because you have declared androidwebservice.com not www.androidwebservice.com
The basic (working) example is over here:
https://reformatcode.com

Virtual Host don't redirect properly with CakePHP and MAMP

I'm developing a web with cakePHP (using MAMP as localhost) and I just configured a virtual hosts to the root of my project.
My /etc/hosts is
127.0.0.1 localhost
127.0.0.1 altair.loc
And my httpd.conf
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Volumes/Macintosh HD/Users/robotThree/www/"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Volumes/Macintosh HD/Users/robotThree/www/ALTAIR/altair/"
ServerName altair.loc
</VirtualHost>
With this I can access to my project typing http://altair.loc and all controllers and actions works perfectly (i.e. http://altair.loc/controller/action).
The problem is that all files accessed statically fails. For example http://altair.loc/css/main.css fails, but it works if I type http://altair.loc/ALTAIR/altair/css/main.css, as if the virtual host wasn't configured.
Do you know what could be happening?
Thank you in advance
Solved. In httpd.conf is necessary to check that Override is for all, it was an .htaccess and mod_rewrite issue:
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>

Why doesn't Apache redirect my IP address to the desired location on my server?

I made a simple page /home/david/mainSite/index.html. I then added a virtual host in Apache to redirect my IP address to this page.
<VirtualHost *:80>
ServerName 74.181.105.228
DocumentRoot /home/david/mainSite
</VirtualHost>
However, when I go to 74.181.105.228after restarting Apache, I get a page with this text instead of "index.html."
Welcome to mydomain.com!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
Why does Apache redirect to the default page instead of "/home/david/mainSite/index.html"?
Here is how my "/etc/apache2/sites-available/default" file looks like.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I discovered the answer! It was tricky.
In "apache2.conf", I originally had ServerName 74.181.105.228, which makes accessing 74.181.105.228 via a browser load the default page for my server.
Changing this value in "apache2.conf" to ServerName mydomain.com solves the problem since Apache no longer directs 74.181.105.228 to the default page of my server. In turn, I can direct 74.181.105.228 to load a page from a certain directory in my file system.
My virtual host block still remains
<VirtualHost *:80>
ServerName 74.181.105.228
DocumentRoot /home/david/mainSite
</VirtualHost

OSX Local SSL not Respected?

I'm clearly missing something, probably something obvious, but I'm just not seeing it. I have a self-signed certificate configured on my MBP (running Apache via Macports). It's a wildcard cert for *.local and I've configured a named virtual host for a site I'm working on, but when I attempt to access it via https, PHP's $_SERVER variables indicate that the SSL access isn't been recognized/respected. Even though I'm accessing https://mynamedhost.local, the PORT key reports port 80 and no HTTPS key exists.
This is a CakePHP site, so the lack of an HTTPS key prevents RequestHandler::isSSL() from reporting true. Any insights would be much appreciated.
Here's my httpd settings output:
$ httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:443 is a NameVirtualHost
default server www.example.com (/opt/local/apache2/conf/extra/httpd-ssl.conf:74)
port 443 namevhost www.example.com (/opt/local/apache2/conf/extra/httpd-ssl.conf:74)
port 443 namevhost mynamedhost.local (/Users/rob/Library/Application Support/MacPorts/apache/conf.d/mynamedhost.conf:17)
*:80 is a NameVirtualHost
default server localhost (/Users/rob/Dropbox/Application Support/apache/conf.d.osx/_localhost.conf:1)
port 80 namevhost localhost (/Users/rob/Dropbox/Application Support/apache/conf.d.osx/_localhost.conf:1)
port 80 namevhost mynamedhost.local (/Users/rob/Library/Application Support/MacPorts/apache/conf.d/mynamedhost.conf:1)
Syntax OK
My namedhost virtual host definition looks like this:
<VirtualHost *:80>
ServerName mynamedhost.local
DocumentRoot /var/www/mynamedhost/app/webroot
ErrorLog /var/www/.logs/mynamedhost_error_log
CustomLog /var/www/.logs/mynamedhost_access_log common
<Directory /var/www/mynamedhost/app/webroot>
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName namedhost.local
DocumentRoot /var/www/mynamedhost/app/webroot
ErrorLog /var/www/.logs/mynamedhost_error_log
CustomLog /var/www/.logs/mynamedhost_access_log common
<Directory /var/www/mynamedhost/app/webroot>
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Got it. In the Macports extras/httpd-ssl.conf file, the SSL engine was turned on and the certificate files defined. I thought this would trickle down to custom virtual hosts, but I was wrong. On a lark, I decided to drop the following into the *:443 virtual host definition:
SSLEngine on
SSLCertificateFile "/opt/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/opt/local/apache2/conf/server.key"
Now everything seems to work as expected. I still think I have something funky going on in my config, but this is going to have to be okay for now. For anyone playing at home, the modified virtual host config looks like this (the *:80 config as shown above didn't change):
<VirtualHost *:443>
ServerName mynamedhost.local
DocumentRoot /var/www/mynamedhost/app/webroot
ErrorLog /var/www/.logs/mynamedhost_error_log
CustomLog /var/www/.logs/mynamedhost_access_log common
SSLEngine on
SSLCertificateFile "/opt/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/opt/local/apache2/conf/server.key"
<Directory /var/www/mynamedhost/app/webroot>
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

subdomains w/o TLD

How do i set up a subdomain w/o a TLD? i have this set under my main config
<VirtualHost *:80>
ServerName bbs.67.777.777.777 #fake bc my server can easily be hacked ATM :(
DocumentRoot /var/www/phpBB
</VirtualHost>
when i goto bbs.serveripaddress i get a Address Not Found error. if i put that above my main config it still doesnt work however the entire site is pointing to /var/www/phpBB instead of /var/www (HUH!?!)
the main v host is
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I'm on a debian box using apache2 if that helps.
I don't think that server name (bbs.67.777.777.777 ) will get you anywhere - unless you have it added to your hosts file... Can you ping that address ok?
Why not just make your website the default... if you don't need a default?
You cannot have a subdomain with an IP address. The best way around this is to have a domain or a free subdomain (such as no-ip) to point at your IP address and create a ServerName for that. Remember to add the domain to your server DNS zones.
or make a domain in your host files and use that.

Resources