Apache Passenger handle 'www' in url - apache

I've an application deployed to EC2 using passenger and apache2.
I've registered a domain (not with AWS) and have two 'A' records pointing to my instance's elastic IP
appname.com.
*.appname.com.
In my apache2.conf file (below), I've got ServerName appname.com
The application is working perfectly when you type appname.com into a browser. But if you put www.appname.com into the browser, you just get the default apache page.
Does anyone know what I put in ServerName to handle both? I've tried adding another ServerName line under the first but it doesn't work.
Thanks for looking
/etc/apache2/apache2.conf
<IfModule mod_passenger.c>
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-5.0.6
PassengerDefaultRuby /usr/bin/ruby1.9.1
</IfModule>
<VirtualHost *:80>
ServerName appname.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/ubuntu/projects/appname/public
ErrorLog /home/ubuntu/projects/appname/log/error.log
RailsEnv development
<Directory /home/ubuntu/projects/appname/public>
# This relaxes Apache security settings.
AllowOverride all
Require all granted
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>

I solved it thanks to this post (shame you can't thank on the other stack sites using your stackoverflow reputation)
Under
ServerName appname.com
you put
AliasName www.appname.com
or even better
AliasName *.appname.com

Related

This site can’t be reached - XAMPP ignores custom domain vhosts

Environment
XAMPP 7.2.4 installed on Windows 10
Apache running on ports 80 and 443
Configuration
C:\Windows\System32\drivers\etc\hosts:
127.0.0.1 www.test.local test.local
C:\xampp\apache\conf\httpd.conf:
DocumentRoot "D:/htdocs"
<Directory "D:/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot D:/htdocs
ServerName localhost
<Directory "D:/htdocs">
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot D:/htdocs
ServerName test.local
<Directory "D:/htdocs">
Allow from all
</Directory>
</VirtualHost>
The problem
When I start Apache and I access to localhost is all right. The problem comes when I try to reach test.local: the browser returns a This site can’t be reached message. It's like XAMPP ignores the custom domain vhosts defined into httpd-vhost.conf file. The same message is displayed with the server off.
This site can’t be reached
The webpage at http://test.local/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
A few days ago the setup was working and the only changes that I made was the new software installation. I mean, no changes in Apache config files.
If all your stack were working correctly before, don't be like me and don't forget to check if some browser extension is blocking your local traffic, like some extension related with an antivirus system.
In my case it was the Kaspersky Protection extension. When something goes wrong, it shows the following graphic.
C:\Windows\System32\drivers\etc
127.0.0.1 test.local
C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/wamp64/www/test"
ServerName test.local
<Directory "C:/wamp64/www/hydroboost/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Have you updated your C:\Windows\System32\drivers\etc\hosts file with a mapping like this this?
add this line to the end of the hosts file
127.0.0.1 test.local
the localhost domain works without this mapping, because the OS already recognizes "localhost" as a built in alias for the loopback IP address
(this suggestion is assuming that you are running and testing on the same local machine)

Unexpected virtual host behavior of Drupal sites on Apache

I'm running an Apache server on a CentOS 7 machine.
A month ago I created a new Drupal site (let's call it site1) under /var/www/html/site1.
Visiting http://<server-ip>/site1 yielded site1 correctly.
Today, in order to provide a test environment for a new customer, I had to create a virtual host for a new Drupal site (let's call it site2).
So I created the following vhost rule:
<VirtualHost *:80>
ServerAdmin test#email.com
ServerName site2.dev
DocumentRoot /var/www/html/site2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
After that I created the site's folder /var/www/html/site2 and installed Drupal. Visiting http://site2.dev yields site2 correctly.
The problem is, if I now visit http://<server-ip>/site1, site2 is shown.
I can't figure out what might be the problem. The two sites are on completely different paths and different databases, so one shouldn't affect the other in my opinion.
Since I literally defined my first vhost today, I was wondering if someone might help me explain the issue. Thanks in advance!
Ok I missunderstood your problem and thought you had 2 domains.
Was your site1 accessed by the IP with no sub directory? In this case :
Change the DocumentRoot to point to /var/www/html then both sites will be accessed by IP/site1 and IP/site2.
If you were allready accessing site1 by the url IP/site1 then you had nothing to change and could access IP/site2 without your new virtualhost wich point only to site2 directory... .
Based on Laurent's answer, this is the configuration I ended up using:
# So all IP only paths continue to work
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName 10.10.10.10 # Server's IP
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
# So site2.dev points to its folder
<VirtualHost *:80>
DocumentRoot /var/www/html/site2
ServerName site2.dev
<Directory /var/www/html/site2>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>

Configure Apache to run website off of port-enabled IP address

To be perfectly honest, I'm not even sure if this is doable...
I've configured my vhosts file in /etc/apache2/sites-enabled which you can see here:
<VirtualHost 159.203.171.140:8080>
ServerAdmin webmaster#localhost
ServerName 159.203.171.140:8080
DocumentRoot "/home/wiki/public_html"
DirectoryIndex index.php index.html
<Directory "/home/wiki/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
CustomLog ${APACHE_LOG_DIR}/wiki_access.log combined
</VirtualHost>
for a digitalocean droplet given at the IP listed in the above hosts file. This droplet has absolutely nothing on it except for the wiki user in /home/ plus the required php, mysql/mariadb, apache stuff.
What I want to be able to do is to go to 159.203.171.140:8080 and see my site without having to purchase a useless domain name.
I'd really appreciate some help with this one.
If you have only one website on the droplet, then you don't need to set up a virtual host. You can use the 000-default.conf, no need for a2ensite.
You do not need the ServerName, which won't work with the IP as a name, you also don't need the IP address in the VirtualHost directive.
So, instead of this:
<VirtualHost 159.203.171.140:8080>
ServerAdmin webmaster#localhost
ServerName 159.203.171.140:8080
DocumentRoot "/home/wiki/public_html"
...
You can use this in your 000-default.conf file
<VirtualHost *:8080>
DocumentRoot "/home/wiki/public_html"
...
The rest of the directive stays as you have it.
Also, one note, if you are using port 8080, then you need go to /etc/apache2/ports.conf and set the Listen to 8080 (restart Apache after doing this).

Apache won't start with added VirtualHost, but gives no error in error log

I am using EasyPHP (version 16.1.1) for Apache server (installed version 2.4.18 x86). I need to add a new VirtualHost, so now the whole VirtualHost section of httpd.conf looks like this:
# VIRTUAL HOSTS
## Virtualhost localweb
<VirtualHost 127.0.0.1>
DocumentRoot "C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www"
ServerName 127.0.0.1
<Directory "C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www">
Options FollowSymLinks Indexes ExecCGI
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8080>
UseCanonicalName Off
ServerAdmin marekbuchtela#gmail.com
ServerName posis
ServerAlias posis.tovarna
VirtualDocumentRoot "C:\Users\marek\is\tovarna\public"
</VirtualHost>
The first one is the default one made by EasyPHP, the second one is added by me. However in this setup, the Apache won't start. When I remove the second VirtualHost, everything works fine, but with it, it just won't start at all. I have checked the error log and there is no output at all.
Any ideas why is this happening/how to fix it?
Thanks
Switch VirtualDocumentRoot "C:\Users\marek\is\tovarna\public"for DocumentRoot "C:\Users\marek\is\tovarna\public"
If by any chance you keep getting the error, show error_log output
There is another instance other than the answer given by ezra-s as to why EasyPHP server won't start and the Apache error log is empty.
When declaring paths in the vhosts file, it is important that the directories referenced in those paths exist. If you provide the following VirtualHost information, for example:
<VirtualHost *:80>
DocumentRoot "D:/MyApp/public_html"
ServerName myapp.local
ErrorLog "D:/MyApp/logs/error.log"
CustomLog "D:/MyApp/logs/apache.log" common
</VirtualHost>
...but you don't have a D: drive, or the directories D:/MyApp/ and D:/MyApp/logs/ don't exist, then you'll get a "silent fail" in Apache when starting the HTTP server from the EasyPHP console.

Rackspace server and CakePHP webroot help

I am moving my cakephp website from my old server to rackspace. I can load my website fine but all the CSS and JS is broken. I'm not sure if it's a Cake setting I'm over looking or a Rackspace setting I'm over looking. I have my cake install in
/var
/www
/rp
/app
/cake
etc
etc
This is the error I see whenever I restart apache. Something isn't lining up. Please, let me know if I need to provide any other information to help resolve this issue. Thanks!
Restarting web server apache2
Warning: DocumentRoot [/var/www/app/webroot] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using x.x.x.x for ServerName
... waiting Warning: DocumentRoot [/var/www/app/webroot] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using x.x.x.x for ServerName
...done.
If the DocumentRoot is not specified in apache2.conf, then it defaults to /var/www
However, I usually like to put it in my vhosts file. Make sure your vhost file is included. For example:
Include /private/etc/apache2/extra/httpd-vhosts.conf
An example of a vhost file is as follows:
NameVirtualHost *
<VirtualHost *>
ServerName www.abc.com
ServerAlias www.abc.com
DocumentRoot /var/www/rp/app/webroot/
ErrorLog /var/log/apache2/abc.log
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>