Can a Virtual Host on Apache access the files of another Virtual Host? - apache

I'm looking to set up a few virtual hosts for different domains for a few friends, and want to know if one virtual host can access files from another host, whether it be via PHP or any other option or if it's totally isolated, so any scripts they can run would only affect their area.

An Apache "virtual host" is just a mapping of a hostname (or ip address or port) to a particular set of configuration directives. There is no "containment" or isolation implied by this; everything is still running on the same host.
If you want to actually isolate applications, consider investigating container technology like Docker (or a virtual machine solution), with a front-end proxy directing traffic as necessary to the appropriate backend.

Related

Use Apache virtual hosts to access local servers?

I was wondering if it's possible to use Apache to request websites on a local network, with apache being the gateway so to speak? On my home network I currently have a Windows box running an ASP.NET site, it has to run under Windows/IIS, a server I'm not particularly fond of, but I can live with it... Alongside this I'm thinking about running an Apache server on a separate machine, for my PHP applications, as well as some other applications (e.g. Plex).o
Ideally I'd like to have Apache on port 80, listening for requests, and using the sort of functionality I have with a virtual hosts file to load content from another webserver on my network, that isn't directly accessible through it's own port. I know I could just run PHP under IIS, or move one server to another port, but there's no fun in that!

How to set a custom website name instead of ip address for local computer?

I can point a url to a directory in my computer by setting /etc/host and /private/etc/apache2/extra/httpd-vhosts.conf files. For instance, when i type sample-app.com in my computer, website under /Users/azad/works/sample-app.com folder is running.
When someone type sample-app.com in another computer in same local network i want to display the same website located on my computer. Is this possible?
By the way, i don't have access to any computer in the local network and i can't do any configuration.
Mac 10.7.5 (I am using mac but if windows is better for this purpose i can use windows too),
PHP 5.3,
Apache 2.2
If you want to accomplish this on windows, use the hosts file on the computers you want to point at that sample-app.com URL mapping your IP address to that URL in all the computers you want that to work on. Then make sure your HTTP server is configured to serve that website under that host name for port 80.
Since you aren't able to configure the local network, the best way to handle this situation is to configure a host name with the website domain's DNS server, such as dev.sample-app.com, which points to the local IP address (seeing as how its on the local network) of the computer hosting the website. This will then allow other computers on the local network to enter this host name to access the webiste.
If you had control of the local network's DNS server or control of the proxy (if they have a proxy), there would, of course, be other options.
Update:
Since you mentioned in your comment that you have control over the DNS server, here is how you could accomplish your goal via the DNS server. First, add a forward lookup zone for sample-app.com to the DNS server. Second, configure the default host for the zone to point to the computer serving up the website content. Now the client computers will resolve the local IP when the user enters sample-app.com into their web browsers. If you need to continue to have access to other hosts on sample-app.com, you might want to try asking about it on serverfault.

creating virtual hosts on a vagrant box

I am trying to setup a development environment based on vagrant provisioned with Chef. I created an environment with Apache (used Chef) and can access web server from my host machine with port forwarding.
I'd like to make my vagrant box to contain several virtual hosts and with shared folders I will define different projects pointing out same box and related virtual host.
What I need to learn is whether there is a Chef-way to create virtual hosts for apache (it maybe other web servers, eg. nginx) under vagrant box or not. Or after vagrant+chef setup should I configure virtual hosts manually with connecting box via ssh? If both options are available, which one is more preferable to apply?
The answer is YES, you can do this using Chef. The choices you have to is to use standard community recipe of Apache2 by Opscode or part of it. You might also want to check discussion here and here
Good practice would be of course to use a recipe/write your own to create virtual hosts and enable them. One of things you want to achieve with Chef is to automate this so that you won't have to do it manually. The complexity of your scenario might demand you to do it differently than what has been tried in links below. You might have to DNS configurations in place of course if you are planning to deploy this places other than your local machine.

How to set up an internal website?

How do I set up a website that's accessible within a small (office) network? I've only worked on localhost (using WAMP) so far and have no idea where to start. Also, is it possible to access that website through a pseudo domain name/alias instead of an IP?
This is of topic here - and wil be covered by lots of basic set up tutorials.
It's exactly the same process, except you need to ensure that clients on the lan can connect to the webserver runing on port 80 - i.e. make sure your firewall isn't blocking the access and that apache is listening on the LAN interface address (the default configs are usually to listen on all addresses).
is it possible to access that website...
Yes - just publish a DNS record for the webserver in your DNS server - or add it to the hosts files on all of the clients.

Error with DOJO when using IP

Strange error with an Project using dojo:
if i call : http://localhost/project everything works like expected.
if i call : http://127.0.0.1/project everything works like expected.
if i call : http://192.168.2.1/project i get the following error (ONLY in IE6!):
"Bundle not found, locale.."
Any ideas?
Iam running Zend Server CE with PHP 5.2
if i add: 192.168.2.1 to "hosts" it works (windows)
Sounds like Zend server is performing some kind of virtual site support using the site name as a partial domain.
I can't say 100% if/how it is beacuse I don't use Zend, but I can explain the principle using Apache as an Example.
There are 3 ways in which a web site can be virtually hosted under a single web server application, this applies to most servers on the market today, Apache, IIS, nginx and many others.
It all boils down to one thing, giving one running server application instance the ability to host multiple individual websites.
The 3 methods of seperating sites are as follows:
By IP address : If you have multiple IP addresses (Usually -but not always beacuse you have multiple network interface cards) then you can tell your server application to listen to one IP for one site, another IP for another site and so on. If you browse to one IP you'll get one site, and likewise the other on the other IP.
By Port Number : If your using only one IP address, then you can bind to multiple port numbers, port 80 is generally the default for web servers, but by browsing to an address and pinning the port number on the end (http://mysite.com:99) you'll force the browser to use that port. You can then have multiple websites listening on different ports and select them manually at browse time as required.
By Host Name Header: This is by far the most common way of supporting multiple sites, all web servers that understand the HTTP/1.1 protocol have to obey a header field in the request that contains the host name, when a request comes in for EG: http://mysite,com/ then there will be an entry in the request header that looks like 'Host: mysite.com' the webserver can then use that to say, oh yes.. I know which one that is.. and it then selects and serves the correct website.
The problems start to arise however when you start to use IP addresses that generally cannot be resolved or have no DNS name, because the web server then doesn't know which hostname to tag it to.
As an example in Apache, if you set up a virtual host, then try to browse that server using just the IP address, you'll get the default server, which in many cases won't even be configured to respond correctly or display anything.
To compound this, going up to web application layer, many frameworks also do their own checks on hostnames and other variables passed to them by the web server, and many make decisions on how to operate based on this information.
If you've gotten to the default web application by IP address, then there's a high chance that the framework may get confused at being presented with an IP address as a host name.
As the OP noted, in many cases, you can add a name to your hosts file and use this as a poor man's DNS substitute, the file to modify can be found in the following locations:
c:\windows\system32\drivers\etc\ - on windows
and
/etc/
on Linux/Unix
The file is generally just called 'hosts' and is a plain text file. Adding a line like:
123.456.789.123 myserver
Will tie http://myserver/ to http://123.456.789.123/
If you can, and your doing a lot of web applications it may be worth setting up your own DNS server, most Linux distros will allow you to install 'Bind' and I do also believe there is a version available for windows too.
I'm not going to go into the pro's and cons of private DNS servers here, it's a whole other subject in itself, but if your likely to be doing a lot of additions to your hosts, then in the long run you'll find it a better option.