Multiple Apache Virtual Host Files with one Document root? - apache

I've set up a single VPS running Apache, with an application installed in /var/www/html/. I have a domain [example-1.com] to the server IP.
I'd also like the same application to be served on [example-2.com]. Something similar to creating an 'Alias' domain.
Is it possible to have two Virtual Host Files configured at one document root?

Yes, no problem. The document roots can point wherever you want them to. If the configuration of the second virtualhost is the same, you could also use the ServerAlias directive.

Related

Two domains with same name different tld? Apache VirtualHosts

So I am following the Ubuntu default style of hosting domains on a LAMP server, and as per widely available knowledge, For each domain to be hosted, I have to create a file with same name but with .conf as the extension, inside the following directory.
/etc/apache2/sites-available
So if I have to host example.com I will be creating a file example.conf with all the Apache directives for that specific domain. So far so good, now if I have to host an additional domain with same name but a different extension, say example.org what should I do?
One solution that is occurring to me is add the virtual host config to that same file beneath the previous code, so is this the way to go or is there any "correct" way?
You create your virtual host with the fqdn, eg, example.com.conf and example.org.conf

Rewrite with multiple symfony projects under same directory

I'm trying to make some personal projects in my development server, like some sort of intranet.
If I divide each project in a different virtualhost, I set in each computer the host file to each server name and I don't have problems with the rewrite rule and the app.php. But the problem is that I can't modify the host file in an android device so I can't access those webs.
What I have in mind is something like this:
I have three symfony projects under my home folder
/home/user/projects/project1
/home/user/projects/project2
/home/user/projects/project3
Then, under the default folder of apache I make soft links to the web folder to every project:
ln -s /home/user/projects/project1/web /var/www/html/project1
ln -s /home/user/projects/project2/web /var/www/html/project2
ln -s /home/user/projects/project3/web /var/www/html/project3
So I can access them this way:
http://server-ip/project1
http://server-ip/project2
http://server-ip/project3
The problem is that I use those url I need to add the default app.php. I've been trying to modify the .htaccess file of each project, but I don't what to modify. I'm using the default virtualhost configuration and the default .htaccess file of each project.
I think that I need to modify the RewriteCond line, but I don't know what to do.
Thanks
I've got a local development environment (it's actually running on a linux server, under my desk, but the same setup would apply to any other configuration of server).
The webserver has a local IP address, reachable from elsewhere on the local network, including from my phone over WiFi.
All the development sites have their own Vhost configured on the server, with a common DNS prefix - something like *.devserver.domain.com.
The DNS is configured so that devserver.domain.com and the wildcard *.devserver.domain.com return 192.168.1.75 (or whatever the internal, static IP address is). This is a public domain name that has an A record to a local-range IP address, but it's entirely valid.
If you don't have a domain name that you can add wildcard DNSs to, you can use a service such as http://nip.io/ - and so the vhost Servername would be something like:
project1.192.168.1.75.nip.io
project2.192.168.1.75.nip.io
... etc
You may end up regularly editing the apache vhost if you internal IP changes at all, and maybe finding alternate wildcard DNS servers (my go-to was xip.io, but that isn't diffcult to do).
You may also be able to use an internal wildcard for an Apache ServerName/serverAlias: ServerAlias mysite.*.xip.io.

Apache2 virtualhost configuration trouble

This is my situation:
I have Redmine and Gitlab in my server which does not have a domain associated, because I will use the server IP address.
I want to configure two virtualhosts in apache2 with SSL in order to serve the above web applications, so I can access them like this:
https://x.y.z/redmine
which is located in /var/www/
https://x.y.z/gitlab
located in /home/git/github/public
I have configured apache by enabling two files in site-enabled: github.vhost and gitlab.vhost. The problem is that I cannot set gitlab to be accessible with
https://x.y.z/github
but only in
https://x.y.z
probably beacuse I do not use a domain but only the IP address of the server, and I don't know exactly how to manage it.
I would need some suggestion on how to correctly set the two vhost files.
Any suggestion?

htaccess multiple domains on one hosting using subdirectories

I've been trying to make the following thing work for hours, with no luck:
I have a vps hosting at digitalocean running ubuntu and xampp, and I have multiple domains pointing to the same ip address.
What I want to do is load files from different subdirectories for different domains.
So when I enter domain1.com into the browser, it loads the files from /htdocs/domain1/, and domain2.com from /htdocs/domain2/.
I've found several examples about this, but all of them had the same problem when I tried accessing subdirectories like this: domain1.com/test, they all redirected me to domain1.com/domain1/test, and I do not want to see the middle part domain1 in the url.
Is it even possible?
I've tried all the answers scattered around the internet searching for "multiple domains on one hosting htaccess", and "htaccess hide middle part of url".
Thank you for reading.
Assuming you're using apache as webserver:
define a VirtualHost for each domain, or host in domain. Give each VirtualHost as ServerName the host- or domain name you want to associate with it.
specify a different DocumentRoot for each VirtualHost. The DocumentRoot is the path to the actual files.
add the hostnames you want te be able to access the web files under to your DNS zone.
When done correctly, you will be able to access the web presence associated with each host- or domain name, without the need to enter any subdirectories in the URL, nor will their names show.

How to setup sub-domains like blogspot

What should do to setup a sub-domain for the users when they sign-up into my site.
What are the infrastructure required? I am using Linux servers.
You can either use a specific DNS (CNAME or A/AAAA) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:
$ORIGIN example.com
foo IN A 12.34.6.78
bar IN A 12.34.6.78
or
$ORIGIN example.com
* IN A 12.34.6.78
The advantage of this latter is that no changes are required to either DNS or Apache configuration once the service is running. The disadvantage is that all such wildcard lookups must (by definition) end up returning the same IP address.
The Apache configuration will depend on your requirements, both for end-user control and security. Note that if the users have permission to run CGI scripts on the server then additional setup will be needed to ensure that that's done securely.
Depending on whether content is static or dynamic this will also affect your configuration:
Use mod_vhost_alias to map individual virtual hosts into their individual directories on the server.
If you really want, create a separate <VirtualHost> section for each known site, but then you'll have to restart Apache each time a new user signs up
Use a single <VirtualHost> and then look at the hostname part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that render the output to figure out which user's content to display.
You can make a CNAME entry/ A Record in your DNS settings, for each subdomain
A CNAME record is a record in your
Domain Management Settings that allows
you to control a subdomain of your
domain.
To automate it along with registration, you can write a script which is executed for each user, when s/he registers.
You can refer to this link, as well, for a step-by-step process for Apache:
How to setup subdomains in apache
(since you mentioned Linux, I assume it must be APache. Please mention if it is otherwise)
Alternate Solution
You can also refer to the wildcard solution, given by Alnitak, in the same thread. I find his is an easier way. :)
infrastructure includes access the the dns server to add a wildcard entry, and rewrite rules in Apache.
Try these answers:
How to let PHP to create subdomain automatically for each user?
How to make subdomain user accounts in a webapp
or this link:
http://jam.jrox.com/docs/index.php?article=76
If your using Linux server's I'm assuming your using Apache as your webserver.
You'll have to setup proper DNS routing for the sub domain as well as a virtual host.
Virtual Hosts are fairly easy to setup but I'm not sure how easy it is to do them on the fly progmatically.
Most of the time it's as easy as editing your apache config file and adding the following:
Port 80
ServerName www.mydomain.com
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost>
The VirtualHost Documention will probably of some use to you.
Apache allows you to specify any number of 'sites' based on subdomains on a single server. Creating a new 'site definition' file with the appropriate subdomain information in it, along with proper DNS wildcards, will do what you want.
In other words, the process is like this:
Setup wildcards so that *.mysite.com directs to the proper server.
When a new user signs up, create the proper Apache site definition file - you'll probably have a base template that you put the right subdomain information into and save.
Make Apache re-read its configuration.
Profit.
IMPORTANT This is based on a Debian-style Apache configuration, where the config files are included in a directory, and the main configuration reads all the config files in that directory. This will simplify things a great deal, because adding/removing subdomains will mean adding/removing files, rather than editing a single file, and so the process will be much easier to automate.