I have a CentOS 7 server with apache. I have multiple virtual hosts running on the server. But one refuses to use the DocumentRoot that are specified for the virtual host in the http.conf file. It will only use the global DocumentRoot that are configured higher up in the httpd.conf file.
Have anyone else come across the same issue. I have been trying for a while now and i am all out good ideas.
Here is an example:
This works:
ServerAdmin uc#site1.com
DocumentRoot /var/www/site1.com/public_html
ServerName site1.com
ServerAlias *.site1.com
ErrorLog logs/site1.com-error_log
CustomLog logs/site1.com-access_log common
This doesn't work
ServerAdmin uc#site2.com
DocumentRoot /var/www/site2.com/public_html
ServerName site2.com
ServerAlias *.site2.com
ErrorLog logs/site2.com-error_log
CustomLog logs/site2.com-access_log common
Related
I have 2 sites linked to domains already.
For this I have 2 conf files into /etc/apache2/sites-available/:
<domain1>.conf
<domain2>.conf
With DocumentRoot /var/www/domain1 and DocumentRoot /var/www/domain2.
In addition, I need to setup the 3rd site direct linked to server IP.
For this I created conf file:
IP.conf (IP is IP of the server):
<VirtualHost *:80>
ServerAdmin <email>
ServerName <IP>
ServerAlias <IP>
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Run:
sudo a2ensite <IP>.conf
And:
restart apache service.
But it doesn't help.
Could you advise how to configure routing?
The issue is the default Apache config always uses the IP address of the server. So that IP.conf will never be loaded.
You need to edit the default Apache config — located in sites-available — to make your changes.
Looking at your config, you are indicating the raw IP address for the ServerName and ServerAlias that will — effectively — defeat the purpose of setting up name based virtual hosts:
<VirtualHost *:80>
ServerAdmin <email>
ServerName <IP>
ServerAlias <IP>
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What happens in a case like this is the configs will be ignored because the default Apache setup will always defer to the IP address of the machine you are on. Heck, it would even use all network interfaces if your server has multiple IP addresses.
For name based virtual hosting to work, you must use the domain/host name in your config. Something like this for domain1:
<VirtualHost *:80>
ServerAdmin <email>
ServerName <domain1>
ServerAlias <domain1>
DocumentRoot /var/www/domain1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And this for domain2
<VirtualHost *:80>
ServerAdmin <email>
ServerName <domain2>
ServerAlias <domain2>
DocumentRoot /var/www/domain2
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now for the IP address host config, you should go into your Apache config directory — /etc/apache2/ on Debian/Ubuntu or /etc/httpd/ on CentOS/RedHat — and look inside the sites-available directory. There should be a file named 000-default.conf:
/etc/apache2/sites-available/000-default.conf
And make the changes you are showing in your IP.conf in there. At a most basic level just change the DocumentRoot to be this:
DocumentRoot /var/www/html/wordpress
Then restart Apache and it should be working as expected.
I'm trying to create a MAMP virtualhost so that I can use my laravel project easier, but whatever I do I get " Not Found The requested URL / was not found on this server " when entering localhost or my vh name (cms.dev)
I tried this : How to create virtual hosts in MAMP?
And this : http://eppz.eu/blog/virtual-host-for-mamp-on-osx/
Even reinstalled MAMP and I still have the same issue, I did everything the same way it's shown in these articles.
Here's my httpd-vhosts.conf config :
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/Desktop/MAMP"
ServerName localhost
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "/Desktop/MAMP/cms/public"
ServerName cms.dev
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
Do you guys know what's happening ???
Thanks
Your DocumentRoot paths are wrong. In MacOS, the Desktop folder is in /Users/[yourusername]/Desktop.
I have two domains I'm trying to host on the same IP. This is what I've been trying, but it doesn't work:
<VirtualHost host1.me:80>
ServerAdmin admin#menet.me
DocumentRoot /var/www/html/host1/
ServerName host1.me
ErrorLog logs/host1-error_log
CustomLog logs/host1-access_log common
</VirtualHost>
<VirtualHost host2.me:80>
ServerAdmin admin#menet.me
DocumentRoot /var/www/html/host2/
ServerName www.host2.me
ServerAlias host2.me
ErrorLog logs/host2-error_log
CustomLog logs/host2-access_log common
</VirtualHost>
What should I put in my httpd.conf?
if you are accessing the urls locally i.e. on server itself,
then u need to add their entries in /etc/hosts file.
eg: suppose ur server ip is 192.168.1.1, thn put following entry in hosts file:
192.168.1.1 host1.me host2.me www.host2.me
save the file...
and then check...
hope this helps :)
So I have 4 Virtual Host. I made the 3 Virtual Hosts 2 days ago and it
all works fine. When I made another Virtual Host the next day, it
won't load up the newly created Virtual Host. So I tried renaming the Server Name of my 1st Virtual
Host which is running.
I changed the ServerName and Alias of www.test1.biboglobal.com to hogehoge.com with still the directory of test1. Saved the file and restarted apache. But when I tried to browse hogehoge.com,it won't load the contents.
I tried browsing the test1.biboglobal.com and it still worked. But
that Server Name does not exist anymore because I changed it to
hogehoge.com.
I've searched all about httpd.conf not taking changes but found no answer. I hope someone can help me.
I also tried removing all Virtual Hosts and restarted Apache. But still, it was able to browse test1, test2, test3.biboglobal.com. Although it only displayed the Apache Test Page, not the index.html inside their respective directory.
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
ServerAdmin webmaster#hogehoge.com //**This was supposed to be test1.biboglobal.com**
DocumentRoot /var/www/test2.biboglobal.com/public_html
ServerName www.hogehoge.com //**This was supposed to be test1.biboglobal.com**
ServerAlias hogehoge.com //**This was supposed to be test1.biboglobal.com**
ErrorLog /var/www/test1.biboglobal.com/error.log
# CustomLog /var/www/test1.biboglobal.com/requests.log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#test2.biboglobal.com
DocumentRoot /var/www/test2.biboglobal.com/public_html
ServerName www.test2.biboglobal.com
ServerAlias test2.biboglobal.com
ErrorLog /var/www/test2.biboglobal.com/error.log
# CustomLog /var/www/test2.biboglobal.com/requests.log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#test3.biboglobal.com
DocumentRoot /var/www/test3.biboglobal.com/public_html
ServerName www.test3.biboglobal.com
ServerAlias test3.biboglobal.com
ErrorLog /var/www/test3.biboglobal.com/error.log
# CustomLog /var/www/test3.biboglobal.com/requests.log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#test4.biboglobal.com
DocumentRoot /var/www/test4.biboglobal.com/public_html
ServerName www.test4.biboglobal.com
ServerAlias test4.biboglobal.com
ErrorLog /var/www/test4.biboglobal.com/error.log
CustomLog /var/www/test4.biboglobal.com/requests.log common
</VirtualHost>
how to change localhost/mysite/web to localhost in bitnami
DocumentRoot "C:/Bitnami/wampstack-5.4.25-0/apache2/htdocs/srd-last/web"
i have configured httpd.conf but it is not working?
i want to call localhost.
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/Bitnami/wampstack-5.4.25-0/apache2/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/Bitnami/wampstack-5.4.25-0/apache2/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
I had a similar problem.
If you look towards the bottom of your http.conf file it has
Include "/path-to-bitnami-lamp/apache2/conf/bitnami/bitnami.conf
This overwrites your configuration of virtual hosts so edit virtual hosts there instead.
This problem only exists in newer version and is mentioned in the documentation -
"In recent versions of BitNami apps the bitnami.conf file defines which configuration for each application should be loaded by the Apache server. This file is located in /installdir/apache2/conf/bitnami/bitnami.conf."
DocumentRoot is the path from the root of your Web server (as in the entire file system) to your Web root (The location of where the files that make up your Web page are located)
ServerName is the name you would type into your Web browser.
For a custom ServerName to work you on local host you also need to edit your hosts file.
I think on Windows it's located at C:\windows\system32\drivers\etc\hosts