I am trying to transfere my website in my new server.
I have an internal adresse.ex: xxx-wwwyyy.net
www.site1.com : production web site
www.site2.com : preproduction web site
In my site-available folder I created some vhost files:www.site1.com and www.site2.com
The problem is that both of them are linked to xxx-wwwyyy.net:
If I create a vhost for xxx-wwwyyy.net and i give it my site folder adress:
/var/www/site/prod ,
then my **www.site1.com** and **www.site2.com** go to the same adresse.
If I delete xxx-wwwyyy.net , all of them go to /var/www/
I am just confuised. has anyone any idea?
hello you are trying to create name-based virtual hosts.. make sure NameVirtualHOst *:80 is uncommented in your httpd.conf ... have a look in here:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
Related
I have a server with an ip: XXX.XXX.XXX.XXX
In my server, i have several projects in the folder /var/www:
/var/www/project1
/var/www/project2/trunk/webroot
...
My 000-default.conf is like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Currently I access into them through the following url:
XXX.XXX.XXX.XXX/project1
XXX.XXX.XXX.XXX/project2/trunk/webroot
...
I have a domain that targets to my server
domain.com -> XXX.XXX.XXX.XXX
My intention is to create a subdomain for each project, and each subdomain points to the target folder of the project:
project1.domain.com -> XXX.XXX.XXX.XXX/project1
project2.domain.com -> XXX.XXX.XXX.XXX/project2/trunk/webroot
(I think the best solution will be that XXX.XXX.XXX.XXX/project2 targets directly to XXX.XXX.XXX.XXX/proyect2/trunk/webroot)
I have read that it will be great that each project has its own .conf file in apache, and enabling each site separately.
But I think that if I create a VirtualHost *:80 for each project (project1.conf, project2.conf) they will be in conflict and I dont know how to do it.
Can anybody help me?
Regards.
Virtual Host is the way to go... create one virtual host for each domain pointing to a folder on your server where to webpage is sotored.
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
</VirtualHost>
Etc... One VirtualHost for each domain / DocumentRoot convination
Soruce: https://httpd.apache.org/docs/current/vhosts/examples.html
##################### EDIT
I have tested it on my own server
Whithout touching the default.conf file I have created two new config files
root#raspberrypi:/etc/apache2/sites-available# pwd
/etc/apache2/sites-available
root#raspberrypi:/etc/apache2/sites-available#
Please ignore the default files I have not touched them I have just created two new files named project1.... and project2....
root#raspberrypi:/etc/apache2/sites-available# ls
000-default.conf project1_domain_com.conf
default-ssl.conf project2_domain_com.conf
root#raspberrypi:/etc/apache2/sites-available#
root#raspberrypi:/etc/apache2/sites-available# cat project*
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project1/"
ServerName project1.domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project2/"
ServerName project2.domain.com
</VirtualHost>
root#raspberrypi:/etc/apache2/sites-available#
ENABLING SITES
root#raspberrypi:/etc/apache2/sites-available# a2ensite project1_domain_com.conf
Enabling site project1_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available# a2ensite project2_domain_com.conf
Enabling site project2_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available#
RELOAD APACHE
root#raspberrypi:/etc/apache2/sites-available# /etc/init.d/apache2 reload
[ ok ] Reloading apache2 configuration (via systemctl): apache2.service.
root#raspberrypi:/etc/apache2/sites-available#
################# SUBDOMAIN EDIT
For example I have a single server with an IP XXX.XXX.XXX.XXX that have multiple domains registered (15 domains now).
I have one virtual host entry for each domain that works this way:
domain1.example.com -> Load the domain1 web index.html page (without /nothing/else )
domain2.example.com -> Load the domain2 web index.html page hosted on another folder expecified on the second virtual host.
And finally ussing a2ensite or a2dissite I enable or disable the website as a web hosting provider do...
If for any reason you need that accessing the host domain3.something.com it redirects to domain3.something.com/something/diferent ... it should be done on your server ussing .htaccess file and its a entirely diferent question :D
An Apache web server for the domain “www.abc.lk” is configured and hosted in a hosting server with the IP address 192.168.2.105. Another domain called “www.def.lk” should also be configured with the same content without any duplication. Explain the configuration of the Apache server with name-based virtual hosting for the above requirement?
You have to configure two virtual host with same DocumentRoot but different ServerNames
http://httpd.apache.org/docs/2.2/vhosts/examples.html
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.abc.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.123.com
# Other directives here
</VirtualHost>
Why don't you just use www.abc.lk as ServerName and www.def.lk as ServerAlias in your vhost configuration ?
And of course be sure that both DNS point to the server.
Here is what I use (I think this link lays out all of the solutions or possibilities):
https://realtechtalk.com/Apache_Vhost_HowTo_Serve_Same_Content_using_a_different_domain_and_IP-1730-articles
Here is another way of doing it that is more simple than symlinking or duplicating content between vhosts:
This would be in your vhost.conf
ServerName differentdomain.com
ServerAlias www.differentdomain.com
ProxyPass / http://yourmainsite.com/
ProxyPassReverse / http://yourmainsite.com/
I have 3 websites running on a cloud server, with the default Apache httpd.conf setting . I have uncommented the NameVirtualHost and configured the 3 websites from VirtualHost, after set up the DocumentRoot and ServerName for each, all worked perfectly but only the site within the default Directory is working for mod-rewrite, which I used for SEO URLs. The other 2 sites are located just one level above the /var/www/html, and are in the subfolder of /var/www/websites/site1, site2. I've tried to use RewriteBase in the .htaccess file to make this work but no success, and I have no idea where in the httpd.conf file I can make any changes to get things right. Please help, thanks.
If I understand you correctly you wish to have 3 separate websites running on 1 Apache server and then be able to have rewrites working on all of them.
You are on the right track using VirtualHosts. You need to stick to using a separate VirtualHost for each website you intend to host.
Given a folder structure as follows
/var/www/
- /websites
-- /site1
-- /site2
-- /site3
You can then setup 3 VirtualHosts for each of your 3 sites:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /var/www/websites/site1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.tld
DocumentRoot /var/www/websites/site2
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.tld
DocumentRoot /var/www/websites/site3
</VirtualHost>
Hope this helps.
I'm pretty new in webserver management. So I rented this server, and setup a LAMP server with MySql and everything is alright in that sense.
The problem is now that I have two different domains (say www.domain1.com, www.domain2.org), and I want each of them to load the website content from a different folder on my server.
How can I do that?
I tried to google some relevant terms, but I couldn't find what that's called.
Thank you for any efforts.
If you use Apache2, you can use the ServerName directive in the VirtualHost configuration:
<VirtualHost *:80>
ServerName www.domain1.com
DocumentRoot /folder1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.com
DocumentRoot /folder2
</VirtualHost>
I'm trying to set up a virtual host on a new VPS using apache 2.x on a Ubuntu server.
When starting apache I get the error " xxx.241.214.xxx:80 has no VirtualHosts", and the url for the site still points to the default location which means my virtual host file isn't taking effect:
<VirtualHost xxx.241.214.xxx:80>
ServerName xxx.co.uk
ServerAlias www.xxx.co.uk
DocumentRoot /var/www/vhosts/xxx.co.uk/httpdocs/xxx.co.uk
</VirtualHost>
Please help, I'm no good at all this server config stuff.
I know its been a while since you posted your question but I thought id throw in my thoughts
We currently run a few internal sites here for different purposes, all of them listen of standard port 80 and apache is set up simply as follows
Listen 80
NameVirtualHost *:80
# Site 1 Comment
<VirtualHost *:80>
ServerName site1.intranet
ServerAdmin administrator#whatever.com
DocumentRoot /var/www/html/site1
</VirtualHost>
# Site 2 Comment
<VirtualHost *:80>
ServerName site2.intranet
ServerAdmin administrator#whatever.com
DocumentRoot /var/www/html/site2
</VirtualHost>
Our DNS is set up to route http://site1.intranet etc to the IP of the apache server and the apache config does the rest.
I always use
<VirtualHost *>
(and ISTR always having problems specifying the IP and port number, which I think is why I do it that way now).