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

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

Related

laravel right server configuration for host several site

I got a laravel project uploaded on a vps, I can't understand how to configure all things to have:
more than one site(laravel project) on the vps; (that is is tricky, because all configuration examples that i've found talking about pointing the root of the server to the public laravel's folder)
having .env and .composer and all the system folders not accesible directly;
wich are the right user and permission to set on the various folders;
In my system ive :
www-data classic apache group with standard privileges;
a non root user, used even to access to mysql and ftp service;
a root user;
I'm using apache2 over ubuntu server 16.04.
According to the Question, I assume that you want to host multiple Laravel Sites on the VPS without messing anything up!Here we go!
Let's Assume that you create the Directories of your site in /var/www directory because it's where your Basic Apache directory will be.Configuration for Site 1:
->Virtual Host for Site 1
<VirtualHost *:80>
DocumentRoot "var/www/site1/public"
ServerName www.site1.com
# Other directives here
</VirtualHost>
-> Directory for Site 1 (Upload your Project here): /var/www/site1
Configuration for Site 2:
->Virtual Host for Site 2
<VirtualHost *:80>
DocumentRoot "var/www/site2/public"
ServerName www.site2.com
# Other directives here
</VirtualHost>
-> Directory for Site 2 (Upload your Project here): /var/www/site2
Here is the Trick! As Laravel have its index.php file in the Public Folder of the Project, Your Domains will point to /var/www/site-x/public folder for the specific site! They will have their own composer and config files in /var/www/site-x/ directories of their own! So, This is how you can host multiple Laravel sites on the same VPS without messing anything up! I am using the same technique! I think it's the only one trick to do so! Let me know if that works!

Can I use apache virtual hosts to have many prefixes?

I'm just learning about Apache virtual hosts. I'd like to have two virtual hosts of the form:
sitea.mydomain.org
siteb.mydomain.org
I own mydomain.org and both sitea.mydomain.org and siteb.mydomain.org of the NS points to the same IP address. I thought I could get the server to point to different webpages by making two sites in sites-available called sitea.mydomain.org and siteb.mydomain.org, but both of those entries seem to resolve to the default site.
Does this sound like a correct configuration, or even something that's possible? If so, can anyone point me in the right direction?
Having those two files, you will need to have ServerName and maybe ServerAlias-Directives in them. For example in the file sitea.mydomain.org:
<VirtualHost *:80>
ServerName sitea.mydomain.org
ServerAlias www.sitea.mydomain.org anothersitea.mydomain.org
DocumentRoot /root/directory
</VirtualHost>
Same goes for siteb. Also, create a symlink into sites-enabled.
You need to use a2ensite after creating a site in sites-available.
It does a necessary job, and put a symbolic link in sites-enabled.

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

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

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

How to create Virtual Host from Apache .htaccess?

I am using Apache Friends XAMPP in Windows (Local Server). I setup the virtual host in httpd-vhosts.conf in an Apache configuration directory like this
NameVirtualHost *:80
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot "E:\xampp\htdocs\example"
</VirtualHost>
This works fine when I browse the URL
http://test.example.com
Is it possible to create virtual host from Apache .htaccess dynamically?
The context for VirtualHost has to be server config. See the Apache docs.
This means that the directive may be
used in the server configuration files
(e.g., httpd.conf), but not within any
or
containers. It is not allowed in
.htaccess files at all.
(Directive Dictionary)
It seems to be impossible. Because your .htaccess is used only after your host is resolved by root configuration files of a server like httpd.conf, apache2.conf.
To put simply, .htaccess in the www directory or in its subdirectories will only be processed after root configuration files are processed.
I mean you type http://host.name and apache finds the destination and uses .htaccess file on the host to perform some operations if needed.