Accessing Virtual Hosts Across a Local Network - apache

I've 2 machine on my local network. On my first machine A, i've creat a vhost mysite.lan and i want access to this vhost with my machine B.
If i don't edit my host file, i do not access.
Do you know if i can access on my vhost without edit my host file ?
My vhost :
<VirtualHost *:80>
ServerName wordpress.lan
ServerAlias www.wordpress.lan
DocumentRoot /var/www/html/www.wordpress.lan/webroot/
ErrorLog /var/www/html/www.wordpress.lan/logs/error.log
CustomLog /var/www/html/www.wordpress.lan/logs/access.log combined
</VirtualHost>
Thank you !

You'll need something on your network to read these requests and forward them to the correct address - in the absence of anything else an entry in the hosts file will do this.
Your router contains DNS servers, either entered manually or populated by your internet service provider. By default, these servers provide lookup information for DNS queries. You can run a DNS server locally, but it's a lot of work to achieve what you're looking for.
See this link for info on doing this on Linux (I'm not sure what OS you're on, but I assume it's either Mac or Linux based on format of your vhost entry):
https://superuser.com/questions/45789/running-dns-locally-for-home-network

Related

Apache multihost does not respect server name

I have two django applications on one machine. I would like to run them on the same address and port. So the user should be point to the correct address according the request domain/host. My current apache.conf file looks like:
<VirtualHost *:80>
ServerName 35.232.14.xxx
...
</VirtualHost>
<VirtualHost *:80>
ServerName www.my_testing_domain.com
...
</VirtualHost>
Note that there is real IP address and real domain and other stuff required by Django app. I build the file according to the documentation: https://httpd.apache.org/docs/2.4/vhosts/examples.html#page-header (apache multiple sites on one IP) and https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04 (django with apache).
The thing is, that every request goes to the first VirtualHost (in this case the IP address). If I switch their order in the apache.conf, then every request goes to the domain VirtualHost.
So one of the sites is working correctly (always the first one).
Why the apache does not respect the server names? What am I missing?
I add Server alias withou "www":
ServerAlias my_testing_domain.com
to the "domain based" virtual host. Now it works.

How to host multiple domains and subdomains on single AWS EC2 instance

I am trying to set up 2 domains (domain1.com and domain2.com) with a few subdomains (app.domain1.com) in AWS and run them on single instance (Amazon Linux, PHP, MySQL).
I have set up 3 hosted zones in AWS Route53 with following configurations.
Hosted zone 1:
domain1.com
Type A
52.108.XX.YY
Hosted Zone 2
domain2.com
Type A
52.108.XX.YY
Hosted Zone 3
app.domain1.com
Type A
52.108.XX.YY
Additionally, I have added following code to the http.conf file in VirtualHost tag.
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot "/var/www/html/domain1"
ErrorLog "logs/domain1-error_log"
CustomLog "logs/domain1-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
DocumentRoot "/var/www/html/domain2"
ErrorLog "logs/domain2-error_log"
CustomLog "logs/domain2-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName app.domain1.com
DocumentRoot "/var/www/html/app"
ErrorLog "logs/app.domain1-error_log"
CustomLog "logs/app.domain1-access_log" common
</VirtualHost>
However, only domain1.com and domain2.com are getting resolved. When I visit app.domain1.com, it gives me a "can't find server" error. Please help how to setup the subdomain - is there problem in Hosted Zone setup or httpd.conf?
Ok, so after about 2 hours of reading up various sites and tinkering, I am all set. Here is how to do this.
Basically, you should not have more than 1 hosted zone (HZ) per domain name, otherwise things are really going to be bad. If you have more than 1 HZ for a domain name, please delete the one that was created for the subdomain.
Each HZ will have 4 records -
Following two records are created by default. Do not edit/delete them.
NS - This is the name server record. If AWS Route53 is not your registrar, use ns-servernumber.awsdns-number.com. and other three (4 total) records to change name servers for your registrar.
SOA - Let this record be. DO NOT TOUCH THIS.
Create following two Record Set (blue button).
A - Leave Name blank. Select A-IPv4 address for Type. In Value enter the IP address for your Elastic Load Balancer or EC2 instance.
CNAME - Add * (asterisks/wildcard) in the name field. Select CNAME from the drop down for Type In Value enter the domain name.
Now create the http.conf file and structure virtual hosts like I have in the question.
Things should work now :)
You can follow the tutorial on this link: http://brianshim.com/webtricks/host-multiple-sites-amazon-ec2/
A common error, according to the link, is:
Did it work? If not, here is one possible cause. There might be
another configuration file interfering with this one. Check for
another .conf file in /etc/httpd/conf.d. Often your primary
httpd.conf will include another .conf file in this directory. Make
sure it doesn’t have some Virtual Host settings which are interfering
with yours.
After you set the configurations, you should run:
sudo service httpd restart
This can be done installing Apache HTTP Server on AWS-EC2 instance and configuring VirtualHost for each DNS or Sub-DNS as suggested by an Amazonian
For brevity read this thread discussion, this official example and techrepublic post.
Hope this helped!

How to use xip.io with several virtualhosts and server names? (local dev)

Is it possible to use xip.io to access local website when using virtualhosts with different server names? (I'm on linux, fedora).
For instance, let's say I have 3 websites I can access locally like so:
- http://localsite1
- http://localsite2
- http://localsite3
I would like to access them with other devices via xip.io:
- http://localsite1.192.168.0.15.xip.io
- http://localsite2.192.168.0.15.xip.io
- http://localsite3.192.168.0.15.xip.io
I can't figure out how to make this work, is it even possible?
Yes, it should be possible. I think you can have as many localsite domains as you want to manage. Check your hosts and httpd-vhosts.conf files.
A server alias in my /etc/apache2/extra/httpd-vhosts.conf works for me. I use a * instead of the current IP in my Network Preferences.
Remember to restart the Apache server after you make a change.
For example, my current local IP from the Mac OS System Preferences > Network says: Wi-Fi is connected to Workalicious2011 and has the IP address 10.0.1.118.
So my /etc/apache2/extra/httpd-vhosts.conf file has the following:
# Ensure that Apache listens on port 80
Listen 80
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/davekaplan/Sites/workalicious.com"
ServerName dev.workalicious.com
ServerAlias dev.workalicious.com.*.xip.io
ErrorLog "/private/var/log/apache2/dev.workalicious.com-error_log"
CustomLog "/private/var/log/apache2/dev.workalicious.com-access_log" common
</VirtualHost>
And my /etc/hosts file has:
##
Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 dev.workalicious.com
On my local network I am able to browse to the following and see my local development site:
http://dev.workalicious.com.10.0.1.118.xip.io/
I have a similar problem where I'm working on one mac and want to test on computers and other devices. Using .xip.io works great when you don't have access to a hosts file, on say a tablet.
If you have access to your hosts file on the computer you can add the IP of the local development host computer and just browse to the same url. It's great for PCs or other Macs. For example, I would add 100.0.1.118 dev.workalicious.com to the testing computer's hosts file and as long as I'm on the local network I can browse to dev.workalicious.com on that testing computer and see the site hosted over on the development computer.
Another approach that I used before .xip.io is Charles, it works great and there are some good blog posts out there on how to setup. It's currently $50 for a 1-4 Users.
( I'm working on try to figure out how to use Pow and Apache for a similar approach, but I don't think it works outside the local development machine. )
for me, server alias work.
ex:
<VirtualHost *:80>
<Directory "/home/michelangelo/www/mysite">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ServerAdmin michelangelo#mystie.com
DocumentRoot /home/michelangelo/www/mysite
ServerName mysite.local
ServerAlias mysite.local.192.168.0.6.xip.io
ErrorLog /home/michelangelo/public_html/logs/mysite_error_log
CustomLog /home/michelangelo/public_html/logs/mysite_access_log common
</VirtualHost>
tested on lubuntu
I was working on my project today and got stuck for a while but I've found a really easy setup which works like a charm.
You setup your virtualhost as you used to (do not have to use the alias xip.io at all tried it today)
Here comes the interesting part, when you edit host hosts file, enter your assigned local IP number before your domain name, e.g. 192.168.10.110 myawesomewebsite.com - which you can access at myawesomewebsite.com.192.168.10.110.xip.io

XAMPP Apache site-root-relative links work locally, fail when accessing dev site via remote machine over LAN

Am trying to set up multiple site development areas on a single server machine, then work on content from other computers over LAN. (Excuse the general wording of my questions, the site keeps preventing me from entering example URLs, etc.)
When I work directly on the server machine, entering
my-virtual-host-name:port#
as the URL everything works beautifully. It correctly resolves all links, image references, etc, as being relative to the site root.
When I connect from a different machine, over our Lan, entering
server-ip-address:port#
I get automatically redirected to a default XAMPP welcome page (So I am at least connecting to the server)
I figured how to setup an Alias statement, so that, for example something like
server-computer-ip-address:port#/alias-for-file-path
gets me to the home page for my site. But subsequently when I click on links, for example
/products-services
which I would want to go to
server-ip-address/alias-for-file-path/products-services
it instead resolves to
server-ip-address/products-services
Relevant settings on the computer running the Apache server
IP Address: 192.168.22.12
In Windows Host file: 127.0.0.1 localhost mySiteName
In httpd-vhosts.conf:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "D:\companysites\newproducts\mysite"
ServerName mySiteName
<Directory "D:\companysites\newproducts\mysite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In httpd.conf (assigning alternate port to Apache, since 80 is otherwise used):
Listen 3399
Have tried a bunch of things not detailed here, trying to figure out how to correctly define some combination of server machine and remote machine virtual host definitions and url settings, as well as much web searching and zero luck so far!
At present you've set it up so all Virtual Hosts are listening for the same connection. Same ip from all ports. *
I figured it out, finally! Hopefully this will be useful and clear to someone else! (I am new to this, so may be obvious to others - there were some basic things I didn't understand and now do...)
In httpd-vhosts.conf file, you can:
Create any number of "Listen" statements, each with a unique port number. So, for example.
Listen 8885
Listen 8886
Listen 8887
Then you can create any number of VirtualHost definition sections, associating one of the above ports with each, for example:
NameVirtualHost *
<VirtualHost 192.168.22.11:3399>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost 192.168.22.11:3388>
DocumentRoot "file-system/path"
ServerName mySiteName
<Directory "file-system/path">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When connecting to the server from a remote computer, it is not possible to use any combination of alias server names and/or alias file path names (at least, didn't work for me - if there is a way, I'd be interested to know). Instead, always enter ip-address:port#, for example, enter, as the URL to one of the defined sub-domains on the server machine:
192.168.22.11:3399

Multiple Apache2 vhosts are pointing to the same website

I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?
Here are my vhost files:
001-psycho
<VirtualHost *:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
002-mahogany
<VirtualHost *:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>
try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf
with this content in it:
NameVirtualHost *
It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.
First,
create a VirtualHost in /etc/apache2/sites-available/somesite,
then a2ensite somesite to make it live.
Finally, /etc/init.d/apache2 restart to restart apache.
If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?
Each domain name needs to have it's own single unique ip address, that's how different sites are found.
By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.
If you want to serve multiple websites, each must answer to it's own unique IP address, ie:
site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111
From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):
&ltVirtualHost 145.25.82.110:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
&lt/VirtualHost>
&ltVirtualHost 145.25.82.111:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
&lt/VirtualHost>
This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.
As for configuring bind/named, that's beyond the scope of this question...