Using Apache VirtualHosts to serve multiple subdomains from same global ip address - apache

I have a domain myexample.com which I would like to have multiple subdomains for, using the same IP address. I want to use Apache VirtualHosts without showing the client that redirection is happening. Here are the rules I want:
www.myexample.com gets content from the /var/www folder
www1.myexample.com gets content from the /var/www1 folder
www2.myexample.com gets content from the /var/www2 folder
The problem here is that all three must run on the same computer all on port 80 and I don't want to use 301 redirection because then the client can see what is happening. How do I configure VirtualHosts to do this? I can't figure out how to use mod_rewrite. Im running Ubuntu 14.04 with Apache2.
Thanks!

To add virtual hosts it is recommendable to write each virtual host in a separate file or write all of the virtual hosts for a specific user in one file. This improves the manageability of your server and makes it easy for you to find which file to edit when you want to change a specific setting for 1 domain.
When editing your apache2.conf file in /etc/apache2 there should be a line that says include sites-enabled/ at the bottom of your file. If it isn't there add it.
then create a new file for either your domain or your user in the sites-enabled folder. For easy editing I would do nano <filename>.conf which will open the editor and set the filename and extension.
Insert the following code into the file.
<VirtualHost 0.0.0.0:80>
ServerName www1.example.com
ServerAdmin admin#www1.example.com
DocumentRoot /var/www1
</VirtualHost>
To get everything on the same IP you could either enter *:80 in place of 0.0.0.0 to listen on all IP's on the system or enter the specific public IP address the server has for enhanced security.
Also, other directives may be required if you want to set specific PHP values or if you want to move your log files to a different file use:
CustomLog custompath/domainname.log
ErrorLog custompath/domainname.error.log
Hopes that solves your problem

Related

Laravel Access forbidden on localhost xampp

I just got stuck in the very begining. I have installed laravel and when i run php artisan serv command then this(Laravel development server started on http://localhost:8000/) line appears but when i access it through browser(http://localhost:8000/) then the following error gets displayed.
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.2
Please help me out. Any help would be greatly appreciated. I am beginner in laravel.
Follow the steps below to create a virtual host:
Change to your XAMPP installation directory (typically, C:\xampp) and open the " httpd-vhosts.conf " and " httpd-xampp.conf " files in the apache\conf\extra\ subdirectory using your favourite text editor.
Add these lines into both files with the following directives:
<VirtualHost *:80>
DocumentRoot "C:\Users\Shivam\Desktop\laravel_project\blog"
ServerName blog.dev
<Directory "C:\Users\Shivam\Desktop\laravel_project\blog">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This contains two virtual host configuration blocks:
The first block is the default or fallback virtual host, which is used for all requests that are not matched by subsequent blocks.
The second block sets up a virtual host named wordpress.localhost. The DocumentRoot directive specifies the directory to be used when serving requests for this virtual host (in this case, the WordPress installation directory), while the ServerName directive specifies the custom domain name for the virtual host.
To add more virtual hosts, simply duplicate the second virtual host block and modify the port number, DocumentRoot and ServerName directives as per your requirements. For example, if you want to use SSL with your custom domain name, you can add a new virtual host block for port 443.
If you plan to have a large number of virtual hosts with very similar configuration, consider using wildcard-based subdomains with your virtual hosts.
Restart Apache using the XAMPP control panel for your changes to take effect.
At this point, your virtual host is configured. However, if you try browsing to the wordpress.localhost domain, your browser will show a failure notice, since this domain does not exist in reality. To resolve this, it is necessary to map the custom domain to the local IP address. To do this, open the file C:\windows\system32\drivers\etc\hosts and add the following line to it:
127.0.0.1 blog.dev
This takes care of mapping the wordpress.localhost domain name to the local machine, which always has the IP address 127.0.0.1
It seems to me that you already have Apache running on port 8000.
Try running the serve command like this:
php artisan serve --port=9000
After it's running navigate to http://localhost:9000

How properly set a website and domain (with subdomains) with apache on ubuntu?

First of all, apologies for my English.
I've been reading and reading guides last week a lot hours with no success. I bought a domain + hosting but due bad performance I've got a cheap vps to use as hosting. Currently my setup is:
A domain .com with an A record pointed to my vps ip.
A unmanaged vps with Ubuntu 14.04.2 64 bits to use as hosting for my wordpress with LAMP stack with default setup (I didn't changed any setting on apache, using default virtualhost).
My site works fine but I'm don't know how create subdomains with different directories. For example, my website.com files are in /var/www/html and I'd like to create subdomain.website.com with the files in other directory, let's say /var/www/subdomain.
I checked a lot tutorials and they say to create a virtual server on apache (I use webmin) and then an A record for the subdomain pointing to the server ip.
The problem is that when I enter to subdomain.website.com I see the content from main domain (/var/www/html) and not from "/var/www/subdomain"
I don't want ask you for a full guide step by step, I just need know where I need to start for achieve a subdomain with a different directory because usually I always used hosting services with tools like cpanel to create subdomains pointed to directories in 2 clicks.
I'm a full newbie with Apache/dns management.
Thanks a lot for your time!
Create a virtual host in Apache by creating a file at /etc/apache2/sites-available/subdomain.website.com.conf
In that file, add the following
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName subdomain.website.com
DocumentRoot /var/www/subdomain.website.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now place your subdomain.website.com files at
/var/www/subdomain.website.com/public_html
Then enable the new virtual host by sudo a2ensite subdomain.website.com
After placing the files, if you get a 403 forbidden error, check for permissions of the DocumentRoot folder.
Refer: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

XAMPP server document root for specific website

I just installed XAMPP, and I've found how to change the document root in the Apache config file, but I only want to change it for a specific site. The reason I need this is because all of my links are absolute links (i.e. /url not just url).
I tried changing it with .htaccess, but that gave me errors saying the limited recursion had been exceeded. So I went and changed that to 200, and it too a really long time, and then said that the recursion had been exceeded.
I would use aliases, but that would mean saying that any request to / goes somewhere else.
So is there anyway for me to specify that files inside of directory dir should have their document root as dir?
Thanks.
I found the solution, but it's a bit involved. You have to change the Apace config file, and the hosts file.
In the Apache config file, I added this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/absolute path/from/C/drive"
ServerName site.local
</VirtualHost>
Then I had to add this in the hosts file:
127.0.0.1 site.local
You can read up more on the virtual host here: http://httpd.apache.org/docs/2.2/vhosts/examples.html

Apache named-based VirtualHost configuration for multiple sites in one host

My problem is simple and i think the solution also.
I search the forums about 2-3 hours and didnt my answer... -_-' .
I got "space" in a host provider. So they gave me a "www" directory.
I have multiple folders in this directory so it's like:
www--
|
/Folder1
/Folder2
/Folder3 etc.etc.....
Each folder represents a website.
So i want to redirect each website to each folder e.g. :
www.example1.com -> Folder1
www.example2.com -> Folder2
www.example3.com -> Folder3 etc....
-BUT- without showing the subfolder of each ...
So this is NOT a solution: www.example1.com/Folder1
This IS a solution: www.example1.com .
How can i modify my .htaccess file in root WWW ?
Thanks in advance !
This has to be done through your http server configuration (like apache).
VirtualHosts is how you split multiple domains across one computer, and their respective .htaccess configuration will give you protection for your site (username/password).
If you just want to split the computer into multiple hosts, you don't need to use .htaccess.
See the following links
Here are some VirtualHost Configuration Examples
Apache HTTP Server Tutorial
Server Config Files
Excerpt from the "example's" link on "Name-Based Virtual Hosts":
<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here ...
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example.org
# Other directives here ...
</VirtualHost>
The configuration file is usually located in /etc/apache2/apache2.conf which then reads from /etc/apache2/sites-enabled/*.conf which are essentially symbolic links to /etc/apache2/sites-available/*.conf - those files are used with the above code to accomplish the results you describe.
You may also be interested looking into nginx, an alternative to apache2.
.htaccess is not what you're looking for. Instead, read up on Name-based Virtual Host Support. You will need to add some entries to your httpd.conf file to point each domain to the correct folder in the www directory. It should be pretty straight forward.
http://httpd.apache.org/docs/2.2/vhosts/name-based.html

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...