Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am facing a very strange issue while setting a virtual host on apache to setup multiple websites using separate IPs.
Virtual host is setup but when i am browsing the website it display content under /var/www/html and displaying site1 and site2 folder instead of access the content under respective directory as mentioned in virtual host file.
Below is the steps and virtual host configuration i setup
Added IncludeOptional sites-enabled/*.conf line in /etc/httpd/conf/httpd.conf file
vim /etc/httpd/sites-available/site1.conf
vim /etc/httpd/sites-available/site2.conf
Hello,
I am facing a very strange issue while setting a virtual host on apache to setup multiple websites using separate IPs. Virtual host is setup but when i am browsing the website it display content under /var/www/html and displaying site1 and site2 folder instead of access the content under respective directory as mentioned in virtual host file.
Below is the steps and virtual host configuration i setup
Added IncludeOptional sites-enabled/*.conf line in /etc/httpd/conf/httpd.conf file
vim /etc/httpd/sites-available/site1.conf
vim /etc/httpd/sites-available/site2.conf
...that you can try to follow. You don't say where you got the steps you're posting, but you've missed a step somewhere. You also say when you 'browse the website', it displays folder. Is that when you try to go to http://site1 (or site2), or when you go to the main address of your server? Have you configured both of those IP addresses on your server?
What's in the error and access logs?? After being an administrator for 12 years now, you should know that those log files are the best place to start.
Both sites are hosted on separate IPs say site1 on 192.168.1.100 and site2 on 192.168.1.101. Now when i access site1 using http://192.168.1.100 it land me to /var/www/html where these two folders are created (site1 and site2) and vise versa.
I went through logs as well but there isn't error related to this because apache is accessing /var/www/html instead of mentioned directories.
This is a strange issue for me because same thing is working on one of the server which we setup a year ago.
With out the full config it would appear that these are configured as Name Virtual Hosts, so using the IP address alone will do nothing as it's the server name that's used to match the Vhost to the relevant DocRoot
If you access an Apache web server by IP address, you will always see the first defined host.
What is the DocumentRoot value of your server? Presumably /var/www/html -- what content is in that directory? That's what accessing by IP address will show you.
Your sample VirtualHost entries both show the same domain name. Again, in that case, accessing by domain name will only show the first defined entry.
You do not need two IP addresses to do VirtualHost...we have ~70 domains hosted on a single IP address. Is the web server listening on both IP addresses? Are both addresses configure on the NIC?
I'm not sure how you have domain names on private IP addresses, either, as you can't set those up in DNS.
Also, your config IP addresses and your later example don't match.
# # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html"
# # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory>
/var/www/html was having default index.html which i deleted and after that it start list directories under /var/www/html on browser.
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"
#
# Relax access to content within /var/www.
#
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
/var/www/html was having default index.html which i deleted and after that it start list directories under /var/www/html on browser.
That's the expected and correct behavior for a directory without a index.html And that's what you'll see when accessing by IP address. You're not supplying a domain name, so there's no way for the web server to direct the request to the site1 or site2 directories.
I bind the virtualhosts using IP as i am testing on local machine.
Below is a content displayed on browser.
PHP Code:
Index of / [ICO] Name Last modified Size Description
However when i change the Documentroot in httpd.conf to /var/www/html/site1 it start working but this is a trick as this will not help to host multiple files.
What is the Listen directive set to?
Are the domain names for the VirtualHosts different?
What happens when you access by domain instead of IP?
Again, you don't need (I don't think it will even work) to have different IP addresses for each VirtualHost
From the Apache docs:
Quote:
Error condition
Multiple Listen directives for the same ip address and port will result in an Address already in use error message.
VirtualHosts are accessed by the domain name, not by IP address.
Set both VirtualHosts to the IP address specified in the Listen directive.
Make sure the domain names are different (I presume they are)
Use http://domainname.com to access the server.
I bind the virtualhosts using IP as i am testing on local machine.
It's not the IP address in the <VirtualHost> directive that binds the web server, it's the IP address in the Listen directive...and there can only be one IP address per port.
# # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 80
ServerAdmin root@localhost
# # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80
# # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "/var/www/html"
# # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None
# # Controls who can get stuff from this server. # Require all granted </Directory> # Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf IncludeOptional sites-enabled/*.conf
Below is my virtualhost file configuration for each host
Note :- Actually this configuration work on my local machine but when i am doing the same thing on AWS instance it is not working and by accessing the virtualhost by IP it pointed to apache default index page.
Note :- Actually this configuration work on my local machine but when i am doing the same thing on AWS instance it is not working and by accessing the virtualhost by IP it pointed to apache default index page.
virtualhost by IP will always show you the default configuration. Apache VirtualHost doesn't work by IP, it works by domain name.
Again,
Set the VirtualHost to the IP address of the server...they will both be the same
Access the server with the domain name defined in the VirtualHost (and yes, you will need the hosts file on the calling desktop configured to relate the domain name(s) to the single IP address, if they are not "real" , DNS resolveable domains)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.