I am trying to configure a virtual host on a dedicated server for one of domains - I have never set up a server before, so unsurprisingly I have gotten stuck. I have been following a couple of tutorials and it looks like I have actually succeeded in setting up the virtual host, however after making the changes my test index page will not load and the standard "Ubuntu" page will not load now either when I enter the server's IP into my address bar.
I have created the subdirectory for the domain files as "/var/www/mysite.com/public_html" and have copied and edited the default ".conf" file so that it looks like this:
<VirtualHost *:80>
ServerAdmin me#mysite.com
ServerName mysite.com
ServerAlias mysite.com
DocumentRoot /var/www/mysite.com/public_html
<Directory /var/www/mysite.com/public_html>
Options -Indexes
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After this I ran the "sudo a2ensite mysite.com.conf" command and restarted apache. When I check run "apache2ctl -S" I get the following response:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server mastnew.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost mastnew.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost mysite.com (/etc/apache2/sites-enabled/ibeka.xyz.conf:1)
alias www.mysite.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
It looks like everything when exactly as the tutorial expected. As I said though, when I navigate to my domain the browser just hangs from thirty seconds or so and then tells me it cannot open the page. If I remove the "mysite.com.conf" file and try again, I land on the "Ubuntu" page. So something is going on with my new ".conf" file or there is some other conflict that is causing the server to freak out.
Any help would be appreciated. Thanks.
This may not be a useful answer if anyone is looking at this later, but it's worth trying if you're stuck. I really don't understand why it worked, but my domain was available after I tried this:
So I disabled the site using "sudo a2dissite mysite.com.conf" and then restarted apache. I checked that it was disabled and that my root index was up online (I'll be hiding/deleting this later). Then I re-enabled the site with "sudo a2ensite mysite.com.conf" and again restarted apache. After this, for some reason, the site became available online and all of my public files are now accessible.
Related
I'm trying to configure a simple ProxyPass using this file (as simple as possible) linked in /etc/apache2/sites-enable form sites-avalable (same file seems to work on apache 2.2 but may be i have done other configuration on previous installation and i canìt remember those configuration)
Note i use an IPADDRESS and not a Server Name but i think this is not the problem.
Note 2: i'm not an apache web server expert :)!
ServerName IP_SERVER_ADDRESS
# Redmine
ProxyPass /redmine http://IP_SERVER_ADDRESS:8555/redmine
# test1
ProxyPass "/test1" "http://IP_SERVER_ADDRESS:9180/test1/"
ProxyPassReverse "/test1" "http://IP_SERVER_ADDRESS:9180/test1/"
# test2
ProxyPass /test2 http://IP_SERVER_ADDRESS:8880/test2
ProxyPassReverse /test2 http://IP_SERVER_ADDRESS:8880/test2
DocumentRoot /var/www
But it didn't work, so the url
http://IP_SERVER_ADDRESS:8880/test2
work fine , but the proxied url
http://IP_SERVER_ADDRESS/test2
did not work , with the error
Not Found
The requested URL /redmine was not found on this server
Output of apache2ctl -S seems strange as apparently no VirtualHost configuration is used (?)
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex proxy: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
Quite sure i'm missing some simple thing but i can't find it!
This answer is tested in Apache Apache/2.4.7 (Debian) ProxyPass.
See /etc/apache2/apache2.conf:
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
previous version was
# Include the virtual host configurations:
Include sites-enabled/
So basically in apache 2.4 (Debian and derivated) you must use file with a .conf extension to limit headache....
In Apache 2.2 the .conf extension in file name is not needed.
Other Details:
In sites-enabled configuration files (a soft link to sites-available) MUST be have an extension .conf so WHATEVER_YOU_WANT.conf
You MUST use a2ensite to enable a configuration, because if the file in sites-available did not have the "right" extension ".conf" it say "ERROR: Site WHATEVER_YOU_WANT does not exist!". So for example if you use a file named mysite and try to enable the configuration mysite with the command "a2ensite mysite" you receive an error. If you use a file named myfile.conf same command will work fine... If you manually create a soft link in sites-enabled to a conf file without the "conf" extension , the site will not work!!
You can create a soft link in sites-available with the right extension (.conf) to a file WITHOUT the right extension alredy peresent in sites-available. In such a case the configuration will work but if you use a2dissite to disable the site it will say "ERROR: Site WHATEVER_YOU_WANT does not exist!"
After finding the solution i found some link around
https://www.linode.com/docs/security/upgrading/updating-virtual-host-settings-from-apache-2-2-to-apache-2-4
First things first .. im pretty new to apache configuration.
I'm trying to configure vhosts locally for an apache
(Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 according to phpinfo()).
Its set up via XAMPP (xampp-win32-5.6.3-0).
Operating system is Windows 7 Home Premium SP1.
So i already read some articles about setting up vhosts (also some in this forum).
My host file looks as follows:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 test.local
My C:\xampp56\apache\conf\extra\httpd-vhosts.conf contains the following code:
<VirtualHost *:80>
ServerName test.local
ServerAlias test.local
DocumentRoot "C:/xampp56/htdocs/test.local"
DirectoryIndex app.php
</VirtualHost>
It is loaded in the C:\xampp56\apache\conf\httpd.conf file.
Include conf/extra/httpd-vhosts.conf
The Module mod_log_config.so is also loaded in the httpd.conf
LoadModule log_config_module modules/mod_log_config.so
(After all editing in the config files i saved them and restarted apache.)
When I type test.local (or http://test.local) in FireFox it always says "test.local was not found". When i call up localhost however its working.
I havn't found any answers yet except to check if the vhost and the host file are set up correctly (which seems to be the case here to me).
Sorry for the long post and I am sorry in case it's just some stupid mistake i made here.
Thx for any help!
EDIT:
Here is also the output from the httpd -S command:
VirtualHost configuration:
*:80 test.local (C:/xampp56/apache/conf/extra/httpd-vhosts.conf:44)
*:443 www.example.com (C:/xampp56/apache/conf/extra/httpd-ssl.conf:80)
ServerRoot: "C:/xampp56/apache"
Main DocumentRoot: "C:/xampp56/htdocs"
Main ErrorLog: "C:/xampp56/apache/logs/error.log"
Mutex ssl-cache: using_defaults
Mutex default: dir="C:/xampp56/apache/logs/" mechanism=default
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
PidFile: "C:/xampp56/apache/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
I found the solution.
It was Avira blocking access to my host file .. disabled that option in avira and vhosts work fine now.
Beside that i needed admin rights which were not set for the account i was working with ..
Situation: ubuntu server 14.04 with apache and bugzilla installed on a dedicated vm.
Everything works well, on bugzilla.myexternal.com, bugzilla.myinternal.xyz and on LAN IP address
Now I want to make other internal servers available on the same external IP, by host name based forwarding, with the same apache instance. DNS records added and resolving correctly for other1.myexternal.com, other2.myexternal.com, etc
(internal DNS already covers/resolves internal names of otherX to local ip addresses for internal use)
After reading through the atricles here and on apache, I thinck I was able to distill the bugzila site-conf and add the other site-conf as intended. However, there are so many contradicting articles with different 'solutions', and in the end I can't make it work. Whatever host is called, I always end up with the initial bugzila site. When I a2dissite bugzilla, then I always get forwarded to the first reverse proxy site (showing that the proxying actually works)
Here is what the site-conf looks like.
bugzilla:
<VirtualHost *:80>
ServerName bugzilla.myexternal.com
ServerAlias 192.168.aaa.bbb
DocumentRoot /var/www/html
<Directory /var/www/html>
AddHandler cgi-script .cgi
Options +ExecCGI
DirectoryIndex index.cgi index.html
AllowOverride Limit FileInfo Indexes Options
</Directory>
</VirtualHost>
other1: (and similar for otherX, all having static internal ip)
<VirtualHost *:80>
ProxyPreserveHost On
ServerName other1.myexternal.com
# ProxyRequests off ->also tried without commenting out
ProxyPass / http://192.168.aaa.ccc/
ProxyPassReverse / http://192.168.aaa.ccc/
</VirtualHost>
apache reload without errors/warnings.
When looking with 'apache2ctl -S' I see that they are loaded correctly. But in all cases (when disabling certain virtual hosts), the site that gets shown is always the default server mentionned by ' apache2ctl -S':
VirtualHost configuration:
*:80 is a NameVirtualHost
default server bugzilla.myexternal.com (/etc/apache2/sites-enabled/bugzilla2.conf:1)
port 80 namevhost bugzilla.myexternal.com (/etc/apache2/sites-enabled/bugzilla2.conf:1)
alias 192.168.aaa.bbb
port 80 namevhost other1.myexternal.com (/etc/apache2/sites- enabled/comfoway.conf:2)
port 80 namevhost other2.myexternal.com (/etc/apache2/sites- enabled/spcway.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex proxy: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: MODPERL2
Define: ENABLE_USR_LIB_CGI_BIN
User: name="www-data" id=33
Group: name="www-data" id=33
Question: what to do to make this work and not always show the default server?
I found the cause, and I'm embarrased to say, but it's down to prescribing the wrong domain and TLD for the other serverNames. We have several doamin names with only different TLD that I mixed up. But they do resolve, due to how our DNS is set up with CNAME records.
As a result, no matching serverName is found by apache and the default is shown.
The good news is (for other users) that the above configuration works, so if you need a reverse proxy and local server combination on this unubtu and apache 2.4, then this is the way forward.
regards,
Christof
I desesperate to get wamp working!
I've installed wampserver 2.5 on my win7 64bits machine.
In the httdp.conf file, I just commented out the line regarding vhosts:
Include conf/extra/httpd-vhosts.conf
The httpd-vhosts.conf contains:
<VirtualHost *:80>
DocumentRoot "C:/Users/Alain/Dropbox/Website/exemples/Grafikart/Petsy_alain.dev"
ServerName petsy.dev
ServerAlias www.petsy.dev
<Directory "C:/Users/Alain/Dropbox/Website/exemples/Grafikart/Petsy_alain.dev">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<RequireAny>
Require local
Require ip 192.168.1
</RequireAny>
</Directory>
</VirtualHost>
(I also tried Require all granted)
I first installed wampserver 2.5 64 bits.
I was able, from my local machine to access http://petsy.dev
But when I tried to access to http://192.168.1.16/petsy.dev from an other machine of my LAN, I was always getting a 403 error (Forbidden):
[Thu Dec 04 14:43:08.519329 2014] [authz_core:error] [pid 11088:tid 776] [client 192.168.1.15:39975] AH01630: client denied by server configuration: C:/Users/Alain/Dropbox/Website/exemples/Grafikart/Petsy_alain.dev
[Thu Dec 04 14:43:08.635335 2014] [authz_core:error] [pid 11088:tid 776] [client 192.168.1.15:39975] AH01630: client denied by server configuration: C:/wamp/www/favicon.ico
I got access remotely to petsy.dev when I added in the remote PC hosts file the line:
192.168.1.16 petsy.dev
In that case, I was able, on my remote machine, to access to the server using 'http://petsy.dev'.
First I don't understand what does it change on the server side and secondly I cannot be satisfied by this solution as I cannot use it on a smartphone.
As I wasn't able to find an answer anywhere, I finally tried to install wampserver 2.5 32 bits!
Same problem! But with a different error:
I can ALWAYS access to my petsy.dev website locally but now, when I try to access it remotely, I get a 404 error (not Found) !!!
Here are the access logs of apache
From my local machine:
xxxx::7d1a:xxxx:9672:xxxx - - [05/Dec/2014:19:22:25 +0100] "GET / HTTP/1.1" 200 40438
From my remote machine:
192.168.1.15 - - [05/Dec/2014:19:22:30 +0100] "GET /petsy.dev/ HTTP/1.1" 404 295
httpd -T answers syntax OK
httpd -S says:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server localhost (C:/wamp/bin/apache/apache2.4.9/conf/extra/httpd-vhosts.conf:23)
port 80 namevhost localhost (C:/wamp/bin/apache/apache2.4.9/conf/extra/httpd-vhosts.conf:23)
alias localhost
port 80 namevhost petsy.dev (C:/wamp/bin/apache/apache2.4.9/conf/extra/httpd-vhosts.conf:34)
alias www.petsy.dev
ServerRoot: "C:/wamp/bin/apache/apache2.4.9"
Main DocumentRoot: "C:/wamp/www/"
Main ErrorLog: "C:/wamp/logs/apache_error.log"
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex default: dir="C:/wamp/bin/apache/apache2.4.9/logs/" mechanism=default
Mutex authdigest-opaque: using_defaults
PidFile: "C:/wamp/bin/apache/apache2.4.9/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: APACHE24=Apache2.4
Please, please which stupid error did I make ????
You dont need the <RequireAny> so just try this
<VirtualHost *:80>
DocumentRoot "C:/Users/Alain/Dropbox/Website/exemples/Grafikart/Petsy_alain.dev"
ServerName petsy.dev
ServerAlias www.petsy.dev
<Directory "C:/Users/Alain/Dropbox/Website/exemples/Grafikart/Petsy_alain.dev">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
Require ip 192.168.1
</Directory>
</VirtualHost>
Additional Info
I dont think you understand what is happening when you create Virtual Hosts.
Basically when Apache see's it has one or more Virtual Hosts configured, you are teling Apache that it is the server for more than one domain name. The important part in that sentence is more than one domain name.
This causes Apache to examine the domain name on each incoming connection. It will then match the domain name to one of its Virtual Hosts definitions and change the DocumentRoot and potentially other parameters to those set in that Virtual Host.
So the important thing is that you use a matching domain name in the browser of the other PC you are using to get to Apache with a domain name it knows about.
This would normally be done by a DNS Server on the real internet, but while you are inside your own local network i.e. safely behind your router you have to use another method. You could setup your own local DNS Server, but thats quite complicated.
So the simple solution is to use the HOSTS file on the other PC's in your network.
So on the other PC (not the PC running WAMPServer), edit the \windows\system32\drivers\etc\hosts file and add this
192.168.1.16 petsy.dev
Then either reboot or do this to reload the windows dnscache
Start a command windows using "Run as Administrator" and execute these 2 commands to reload the cache
net stop dnscache
net start dnscache
Now you can use the correct domain name from the browser on the non-wampserver pc like so
http://petsy.dev
And the browser will find that petsy.dev lives on ip address 192.168.1.16. When the connection is made with 192.168.1.16 it will be using the corretc domain name i.e. petsy.dev and apache will find the virtual host and set everything as per the VH config and server pages from the correct folder.
here is a great tutorial
Project Links do not work on Wamp Server
Answer #1 worked for me
I'm running windows 7 64 bit
I have wampserver2.5 (64 bit) installed on a hd assigned to letter A
All my dev sites are located on A:\websites
In A:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf I have this
<VirtualHost *:80>
DocumentRoot "A:/websites"
ServerName localhost
ServerAlias localhost
<Directory "A:/websites">
AllowOverride All
Require local
</Directory>
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "A:/websites/example.dev/www
ServerName example.dev
ServerAlias www.example.dev
<Directory "A:/websites/example.dev/www>
AllowOverride All
Require local
Require ip 192.168.10
</Directory>
</VirtualHost>
On the computer running wamp I adjusted the host file as follows
127.0.0.1 example.dev
::1 example.dev
On the local remote computer I've added an entry to the host file as
192.168.10.100 example.dev (this is the ip address of the computer running wamp)
next step is to clear your dns cache
open a terminal on the windows box that's not the web server
type "net stop dnscache"
type "net start dnscache"
Open a browser and point it to example.dev and it works
hope this helps
It APPEARS I have everything set the right way, after hours of reading/trying a dozen or so tutorials on setting up virtual hosts. Basically, after upgrading my Ubuntu distro (I know, right?), Apache upgraded to 2.4 and everything broke. After trying to figure that out, I just decided I blew everything out and started anew. PHP/Apache are current.
I'm getting the root index ("It Works!") returned, but not the DocumentRoot I specify.
/etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
# Indexes + Document Root
DirectoryIndex index.php index.html
DocumentRoot /var/www/domain.com/htdocs/
# Logging
ErrorLog /var/www/domain.com/logs/error.log
CustomLog /var/www/domain.com/logs/access.log combined
<Directory "/var/www/domain.com/htdocs/">
Options Indexes FollowSymLinks Includes
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I typed in "sudo a2ensite domain.com.conf" and that is showing up in /enabled-sites as you would expect.
apache2ctl -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server domain.com (/etc/apache2/sites-enabled/domain.com.conf:1)
port 80 namevhost domain.com (/etc/apache2/sites-enabled/domain.com.conf:1)
alias www.domain.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
Hoping that it's something stupid I'm overlooking, because it's been a frustrating night and I've tried everything I can think of so I wouldn't have to bother you folks with this (sorry!). I'm not getting any errors from Apache when I start/restart, nor am I getting anything in any error logs. Not sure this is applicable, but the DirectoryRoot permissions is set to 755.
update (11/05/13)
Apparently the "magical fixer fairy" swooped in and resolved this. There is no cache engine installed to my knowledge (unless Apache 2.4 installs with one by default?), so I'm not sure what could've changed itself to make it resolve to the correct directory over the weekend (in which I did not work), but there you go. Just for the hecklers: yes, I had restarted apache (a million times) so that wasn't the fix.
Got the same problem when upgrading to the "saucy" release of Ubuntu. In my case I had several configurations ("sites-available") which did not had the suffix ".conf".
Since the apache2.conf has a directive that only includes enabled sites having this suffix the only configuration that was properly loaded was the default one.
Therefore I suggest that you remove all links in the "sites-enabled" folder, make sure that all your configurations in "sites-available" do have the suffix .conf and enable your sites again using the "a2ensite" program!
Regards, Garth
Are you sure the default vhost file isn't what you are hitting? Make sure the only config enabled is your new vhost first using the a2dissite command and restarting apache.
Then check your access logs specified in your vhost to see what it's actually pulling.
# Logging
ErrorLog /var/www/domain.com/logs/error.log
CustomLog /var/www/domain.com/logs/access.log combined
SHOULD BE SPECIFIC TO YOUR VHOST:
# Logging
ErrorLog /var/www/domain.com/logs/error-example.com.log
CustomLog /var/www/domain.com/logs/access-example.com.log combined
I know this is an old question, but still there was not a real answer. I've experienced the same problem today and it seems that restarting the service with:
service apache2 restart
or reloading with:
service apache2 reload
as suggested by a2ensite "is not enough" or does simply not work. I restarted the service a few times without result. Then i did a:
service apache2 stop
and afterwards restarted the service with:
service apache2 start
And this solved the problem. Strange to see this behaviour but it might be caused by a misconfigured runscript.