set up a vhost with vagrant - vagrant

I'm having troubles with setting a vhost with vagrant.
I've configured my host file on my host (192.168.33.10 local.dev). Yet I don't know how to set up my vhost within my VM and how to access it. And I don't want to use puppet or chef or other as I want to understand what I'm doing... :)
At the moment here are my settings of my vhost:
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/support/mysite
<Directory /var/www/html/support/mysite>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
The problem is I don't really know what I should put as server name or alias and how to access it then.
Thanks for any help !!!

If you already added all the sites you want to run as virtual ones on your host file (all with same IP), then all you need to do is add multiple "VirtualHost" configurations to your apache conf file and use the same "site.dev" name you defined. Apache will read that and direct to the correct "DocumentRoot".
Here is a snippet with two sites defined. Just add more definitions for more sites:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/site1/
ErrorLog logs/site1_error_log
CustomLog logs/site1_access_log combined
ServerName site1.dev
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/site2/
ErrorLog logs/site2_error_log
CustomLog logs/site2_access_log combined
ServerName site2.dev
</VirtualHost>

You don't need a vhost as long as you are serving only one site per machine - local.dev in this case. You can leave the default apache2 configuration.
You need to understand what virtual hosting is actually for to see this:
The main purpose of virtual hosting is the possibility to run multiple web sites with different DNS domain names on one single machine having only one public IP address assigned to it. While there are many websites which would never exhaust the physical power of a server because of their low traffic, the most obvious advantage is that the number of available domains is now independent from the number of available IP (v4) addresses, which is very limited.
This is being achieved by a change in HTTP which was launched in version 1.1. The change adds the Host header to the HTTP request which contains the servers domain name. A HTTP server normally would not have this information: "What was the hostname used by the client to access me", as the DNS resolution will happen before the client issues the HTTP request and the server will then being accessed by it's IP address.
Having the information from the Host header, the server, while being accessed by it's IP address, can decide which site should being served. Multiple sites will then have different document root folders for that.
However, you are serving just a single page from your vagrant box, therefore setting up a virtual host isn't required. Just use apache's default one.

I think there is a more elegant solution to the issue of VHosts on your Vagrant Box.
Set your Virtual hosts directly in your Vagrant file so your configuration can commit to git.
Check out the instructions Setting VHosts in the Vagrantfile here:
https://github.com/onema/vagrant-lamp-development#creating-custom-vhosts
Docs on Chef Solo Here
https://docs.chef.io/chef_solo.html

Related

Apache: ip connection works but not localhost

Earlier today I successfully connected to my Apache server both via http:/localhost and IP address. I turned off the server briefly and when I ran it again, I was only able to connect via IP (which connects successfully from my computer as well as others in the network).
I checked to make sure that my ServerRoot and DocumentRoot were C:/Apache24 and ${SRVROOT}/htdocs respectively as well as that all my server-related files were in htdocs. Additionally, I verified this issue on both Chrome and Firefox (where I also tried clearing the cache).
Any suggestions regarding how to fix this would be greatly appreciated.
Here are the lines I referenced in my httpd.conf file (spliced together):
Define SRVROOT "C:/Apache24"
ServerRoot "${SRVROOT}"
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
I would be happy to elaborate on any pertinent information I may have neglected
By setting the "Listen" setting to a specific IP address and port as opposed to a port, I stopped my computer from accessing the site via localhost. By updating the httpd.conf file to read "Listen 80" I resolved this issue.

Hosting multiple site on apache server in windows 2012 server

I am trying to host two sites on apache 2.4 server which is running in windows 2012 server. I have added vhost entries for two sites one running on 80 and other on 8080.
Sample vhost entries:
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/www/example2"
ServerName www.example2.com
</VirtualHost>
With this configuration both the domain points to site running on port 8080. Considering above sample, sites opens same code in directory /www/example1 on both www.example.com and www.example2.com domains.
But if I access site with I.P. like http://198.21.22.1:80 and http://198.21.22.1:8080 the sites work fine but through domains it does not.
We have a load balancer in between which point to the actual server.
Need to know what configurations or setting if any I have missed.
I have added Listen entries for 80 and 8080 in httpd.conf file.
UPDATE
On further analysis I found that, from different systems different version of site opens up. Example, from my system both the domain opens up code running from /www/example1, but from my mobile client it opens up code running from /www/example2 for both domains.
So, I checked from some other system and found that it opens code running from /www/example1 for both domains and again from some other system it opens up code running from /www/example2 for both domains.
We have a load balancer in between which redirects to the http server on which /www/example1 and /www/example2 are present. Currently I do not have access to this load balancer, but can load balancer be cause of this issue?
Thanks,
Uday
I just added virtualhost entries with same port 80 for both sites with different servername.
Issue was with tow systems being present had to make changes on both server in the load balance cluster.

How to create sub domains for a live server on xampp?

I know that this is a duplicate, but all the other answers I read didn't work for me.
I want to create sub domains for my Apache web server, I want to either be able to access it by one of the following. I just found out that the only people who can access the website are users on my network, do you know why?
sub.domain.com
sub.localhost
sub.000.00.00.00 (Hidden for security)
sub.127.0.0.1
I tried editing the vhost.config file and manage to break Xampp. I am reinstalling it as I type this.
Also is it possible to host multiple websites on a single server? Please explain to me all of this, I been playing around with Xampp and Goggling for too long now.
The error I am getting is the server isn't responding to sub.localhost, but it is for localhost.
httpd-vhost.config
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site1"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site2"
ServerName sub.localhost
</VirtualHost>
errors.log

virtualhost on xampp and accessible from external device

I'm running XAMPP on my WIN7 laptop for developing websites. Now I use virtualhost and a modified hosts file, so I can access my website "www.thisshouldbemysite.nl" through this URL. But it will be loaded from my XAMPP server.
For me locally, this is working fine. I can do what I want. But I also want to access this server from an external device, e.g. a smartphone or tablet so that I can see how the site is rendered on other devices. But entering the IP address of my XAMPP PC in a tablet browser will bring me to the C:\xampp\htdocs directory and I'm unable to access the C:\xampp\htdocs\thisshouldbemysite.nl directory.
Does anyone has an idea of how I can configure my server to get both working (local and remote). Remote should be in the same local network!
Here you can find my current settings.
hosts:
127.0.0.1 www.thisshouldbemysite.nl
httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot C:\xampp\htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:\xampp\htdocs\thisshouldbemysite.nl
ServerName www.thisshouldbemysite.nl
</VirtualHost>
I want to cover a few things to give you the full picture, maybe if you better understand each part of the process then you can identify where your problem is and therefore find an answer.
The first thing we need to understand is how your browser knows where to go when you type in a domain name. Your browser will check your local hosts file, then your local DNS cache, then make a request to a DNS server. The DNS server is either set automatically by your ISP / DHCP, or set manually in your internet connection settings. So, making a request to a domain name, your browser/OS will check those places in that order for matching entries. If no entry is found, then the domain name will not resolve.
A DNS server can have different kinds of entries. It can tell you where a domain name is hosted, it can tell you where a subdomain is, it can point a domain name to another DNS server...its a flexible multi-use spot where a domain name can point to anywhere. Also depending on the kind of DNS entries are set for a domain name, your browser will automatically know if it needs to ask another DNS server for where a domain name points, or if that it the final result it is looking for. Improperly setup DNS servers can cause a user to get stuck in a DNS loop - where one DNS points to another DNS, and the 2nd DNS points back to the first DNS. These kinds of things are very easy to figure out.
The Hosts file is basically like a local, manually set DNS-like system. It allows you to say that "any.domain" is at "any-ip-address". In this manner you can locally over write or disregard other DNS resources. It's good for local stuff, but if you are going to want to access things from over the internet or by many devices, I highly recommend using a DDNS service, which I will go over below.
---Apache VHost File---
In the vhosts file I set a default vhost. This way, if I type in my IP or a domain name that doesn't have a vhost explicitly defined, I still get some kind of response from my web server. This is just my preference, but totally unnecessary. After I set a default, I explicitly define what domains/subdomains I want to serve.
NameVirtualHost *:80
##############localhost
ServerAdmin webmaster#localhost
DocumentRoot "D:/xampp/htdocs"
ServerName localhost
<Directory "D:/xampp/htdocs">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
########othersite.local.whatever
ServerAdmin webmaster#localhost
DocumentRoot "D:/xampp/othersite.local.whatever"
ServerName othersite.local.whatever
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
After your VHost file is saved, restart apache. If apache starts then stops running automatically, then you probably have an error in your apache config / Vhosts file double check your work, try to start apache after saving each change you make until it works.
---Windows Hosts File---
Unless you have a DNS server setup, you will want to modify your Windows Hosts file in order to tell your machine that othersite.local.whatever points to your apache server. What this file does is locally point a domain name to an ip address. It does not effect other computers, it is only for this one machine that is also running your server.
The hosts file is located C:/windows/system32/drivers/etc/hosts
Depending on your windows permission, you may need to copy the hosts file to the desktop first, open it up with notepad or your fav text editor, make your modifications, save it and copy it back to its original location. On a new line, add a new entry:
127.0.0.1 othersite.local.whatever
After you save your hosts file back to C:/windows/system32/drivers/etc/ you should now be able to access othersite.local.whatever on the server machine without issues. If you have other local windows computers, you can modify their hosts files to point to the server's ip address (usually something like 192.168.1.xx) so that those computers can also access the vhost at othersite.local.whatever.
192.168.1.?? othersite.local.whatever
---Addressing your problem through alternate means---
Depending on what your needs are, you can do a couple things.
1) Modify the vhost file on all windows computers, do some research on how to do it on other devices. If all the devices think that othersite.local.whatever points to your server, your server should respond with the proper vhost page. That is how it works weather on a local network or WAN / internet.
2) Setup a local DNS server, point all your devices to your DNS, and add an entry in your DNS to point to the domain to your server. This is a complicated task if you have never done it before, but you might find it useful.
3) Set up a Dynamic DNS (DDNS). This one is a little complicated, but it is actually pretty easy to do. It can really help you open up your options.
Here is how it works - your home internet connection's WAN IP probably changes from time to time - A Dynamic IP assigned from your ISP by their DHCP service. If you turn your internet modem off and on again, your IP probably changes. This is no good because if you have an external DNS or link that points to your IP in some way, and your IP changes because either your power turned off and on or DHCP renewed your IP lease with a new IP, then you are cut off from your server. So to get around this we have something called a Dynamic DNS. You sign up with a DDNS service (many of them are completely free), you run a little DDNS program on your PC. The DDNS program simply checks your IP address every few minutes and updates the DDNS servers with your IP. If your IP changes, then within minutes the DNS servers are notified of the change and you are back to accessing your server.
To get this all setup you need to setup your local internet connection to forward incoming connections on port 80 (your website probably runs on 80 unless you changed it) to your web server. Set your server's local IP address to a static one (so it doesn't change on your local network, you know something like 192.168.1.100 or whatever suits your needs) and modify your internet gateway/modem/router to forward everything on port 80 to your server PC.
I like to use a free DDNS service called No-IP (http://no-ip.com/). It's free, simple and reliable. Create an account with them, pick a single subdomain - you could go with something.bounceme.net or other predetermined free DDNS names. After you pick a name, install the DDNS / No-IP program on your server PC. Now something.bounceme.net will always go to your home IP. If you setup port forwarding properly, anything on port 80 will automatically go to your webserver.
Now the last step is to get a normal domain name to point to your home IP instead of something.bounceme.net. You could either pay No-IP to do some fancy stuff, or you can do it the free way which is what I will explain here.
I used Godaddy as a domain registrar the last time I did this, and everything has changed so much, you may need to call Godaddy or your domain registrar and ask where/how you can do this with their service.
First is, you need a domain name. Let's say you own homesite.com and let's also say you want laptop.homesite.com to point to your home web server.
For the domain homesite.com, add a DNS record of the type CNAME with a key of "laptop" and a value of your DDNS name "something.bounceme.net". This will make it so that laptop.homesite.com will resolve to your home IP address. Make sense? Now when you type laptop.homesite.com the DNS will tell it to check something.bounceme.net and that will resolve to your home IP.
There are some limitations to the CNAME entry. You can't forward just "homesite.com" to your DDNS IP. You basically have to use a subdomain entry, like laptop or home or something like that. One thing you can do, though, is use the 'subdomain' entry WWW, so that www.homesite.com will point to your home IP. If you use Godaddy, you get a free limited hosting account with your domain name that shows Godaddy ads on it. You can set this account up for "homesite.com" and place some redirect code in it to send users to "www.homesite.com". This way, people type homesite.com and automatically get sent to www.homesite.com.
I hope this is all making sense.
So let's review - Set your servers Static IP, setup port forwarding so the port 80 points to your server's local IP, setup a DDNS (like http://www.no-ip.com) and install their DDNS program, set a CNAME with your domain registrar so that www.yoursite.com points to your home server (CNAME www -> your-ddns-url.bounceme.net). Now you should be able to access your server from anywhere in the world at www.yoursite.com, from inside your local internet connection or from a starbucks.
You can also setup port forwarding for an FTP server (usually 21) to remotely edit your website or access your home files. You can do all kinds of things when you can remotely access your home PC.
I hope this short walk-thru will help you understand each part that is necessary to access an apache VHost across all devices. I like using the DDNS setup/option because you don't need to setup hosts file for each device or anything like that. It's just like accessing a regular website!
Questions or comments welcome. I literally just wrote this all out off the top of my head, I hope it helps.
Have you tried this configuration for your virtual host?
<VirtualHost *:80>
DocumentRoot C:\xampp\htdocs\thisshouldbemysite.nl
ServerName localhost
</VirtualHost>
in this file there is virtual hosts definitions:
C:\server\apache\conf\extra\httpd-vhosts.conf
one virtual host already exist and you are using as default "localhost".
create another one for new project with different port number (81 is here)
<VirtualHost *:81>
DocumentRoot "C:\server\htdocs\YOUR_PROJECT_FOLDER"
ServerName YOUR_SERVER_NAME
<Directory "C:\server\htdocs\YOUR_PROJECT_FOLDER">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
than in this file contains default ports which apache will listen
C:\server\apache\conf\httpd.conf
#Listen 12.34.56.78:80
Listen 80
Listen 81
add your new ports here
Now you can open http://YOUR_SERVER_NAME from local machine
and open http://local_ip_adress_of_your_machine:81 from other local network connected pc.
Windows users need to add new server name to the C:\Windows\System32\drivers\etc\hosts file
127.0.0.1 YOUR_SERVER_NAME
i hope it helps someone who need

Configure websphere httpd.conf and plugin-cfg.xml

i have an application which is deployed on websphere application server with ibm http server.I want to change the domain name.I have figured out that changes will be required in httpd.conf file. in the servername tag.also plugin-cfg.xml needs to be changed.How should i modify these files.and how will the changes be reflected.
And are there any other files/properties files where i have to chnage the domain name.
Thanks
You don't want to edit plugin-cfg.xml manually (except in very rare cases). The hostnames in there come from the Aliases defined for the WebSphere Virtual Hosts.
By default, those usually have *:80, so changing the server domain name would require no changes at all. For instance:
<VirtualHostGroup Name="default_host">
<VirtualHost Name="*:9080"/>
<VirtualHost Name="*:80"/>
<VirtualHost Name="*:9443"/>
<VirtualHost Name="*:5060"/>
<VirtualHost Name="*:5061"/>
<VirtualHost Name="*:443"/>
</VirtualHostGroup>
If the WebSphere Virtual Host that your application is using does specify an Alias with a particular domain name, you just change the domain name there.

Resources