So I have my default htdocs folder, but I would like to add an additional one, which is outside. My problem is that I don't have any idea, how I can do this. I'm only knowing, how I can change the directory, but that's not the way, I would like to go.
I've read something about an Virtual Host, which can be added. So I tried it, but with any result, but haven't expected, that it would be that easy... even the httpd.exe said, that the syntax was ok. But there wasn't any further explanation, how I could go on.
Does anyone know, how I can add an additional one?
Thanks in anticipation!
Just add a different DocumentRoot directive to each Virtual Host section then you have a different document root for each virtual host.
Related
As documented by Apache under Using Name-based Virtual Hosts:
If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default virtual host.
Currently, the template at /var/cpanel/templates/apache2_4/main.default generates such a default VirtualHost (per IP address) with DocumentRoot [% serverroot %]/htdocs.
We would instead like the VirtualHost that is generated for a particular user to be that default. What is the best/recommended way of accomplishing this?
My current thinking is to place the user's (compiled) VirtualHost directive in /usr/local/apache/conf/includes/pre_virtualhost_2.conf, but this obviously won't be managed by WHM should the user's configuration change.
Is there a better way?
In general VirtualHosts matches the DNS entries, including wildcards.
Your situation seems to me like you are activating a new site and while the DNS is ready, the hosting isn't available yet, so you want to temporary display a specific VirtualHost.
I've had a similar problem in the past, and solved it by creating an .htaccess inside the default VirtualHost that redirects to the site I want.
This also has the benefit that the user is clearly viewing the real hostname in his browser.
I know that this isn't the solution you wanted, however I don't think there is any other way to accomplish this, because this has limited applications in normal usage (unusual behaviour).
A bit old school I know, but url masking using a frame on your default page could be the easiest thing to do here?
Create an .htaccess that proxies all requests back to localhost but on an internal port. Then add a Listen directive for the new port and a VirtualHost for that port that is the default you want.
I should mention that this is ugly, but I think it satisfies your needs.
We currently use scheme where we first include specific default VHost config file, like so (that is before any VHost definitions):
Include conf.d/vhost.d/default.conf.first
Include conf.d/vhost.d/*.conf
This way VHost defined in conf.d/vhost.d/default.conf.first is always first.
Okay, so this is what I ended up doing:
Copied /var/cpanel/templates/apache2_4/main.default to /var/cpanel/templates/apache2_4/main.local.
Edited the newly created copy to remove the default VirtualHost directives (I inserted [%- IF 0 %] before line 344 and [% END -%] before line 385).
Edited /var/cpanel/conf/apache/primary_virtual_hosts.conf so that the name of the desired default host was specified for the desired IP address(es).
Ran /scripts/rebuildhttpdconf.
Manually verified /usr/local/apache/conf/httpd.conf.
Gracefully restarted Apache.
I would like to have a subdomain (webmail.inkieweb.com) for my website which points to the same folder as www.inkieweb.com/webmail (/var/www/webmail/), but whenever I access the subdomain, I'm instantly redirected to inkieweb.com (/var/www/) instead. This is bothering me as some of my clients are requesting subdomains and I have no idea why they're not working.
EDIT: I was previously working with a CNAME. I removed that and added an "A" record instead. Now it's not redirecting. It is still loading /var/www/ instead of /var/www/webmail/ though.
These are what I think are the relevant files on my server: http://pastebin.com/Gf6ZSjPv
Note that even though the last two files have the full hostname in the <VirtualHost inkieweb.com:80> section, I have also tried having everything with *:80 instead. Still nothing.
The only thing that happens sometimes is that when I'm messing around with a2ensite and a2dissite, instead of loading the home page, http://www.inkieweb.com starts loading the webmail instead.
Please help me. I don't know what else I can do.
Do you get any errors when you start up apache? Things like inkieweb.com has no virtualhosts?
Are there any virtualhosts defined in your httpd.conf file that may be overriding the one your working with?
I would stick with the *:80 and make sure your have serveraliases for each one that make sense and that the server aliases are not overlapping. You can use grep to find all of them.
Strange error. Was trying to figure out why a virtual host was not working using a setup I've used a hundred times.
DocumentRoot "/var/htdocs/directory-name/"
<Directory "/var/htdocs/directory-name/">
Gave me a 403 error no matter what I tried
DocumentRoot "/var/htdocs/directoryname/"
<Directory "/var/htdocs/directoryname/">
Did not. Has anyone else ever experienced this? I didn't paste the entire virtual host entry, but this was the only difference between what worked and what gave me a 403. I'm totally bewildered.
This should work if you have a physical folder "directory-name" at "/var/htdocs". Could be some unrelated problem otherwise.
Perhaps you forgot to add an entry like
127.0.0.1 test.directory-name.com
in C:\Windows\System32\drivers\etc\hosts ? (if using a test environment on Windows)
Also, double-check any .htaccess files you have for unwanted Rewrites / redirects
I wasn't aware of this, and it is kind of funny; when you name a directory icons in the root of your host, then if you point your browser to host.com/icons, apache does not read from that directory and shows you a listing of Public Domain Icons.
I added an icons directory to the root and placed a key.png file in that directory, yet accessing that image results in 404. I tried to find if/where this has been documented and how it could be turned off. I found nothing. Could someone provide a pointer?
P.S. I am using XAMPP 1.7.3 which basically is a WAMP and has Apache 2.2.14
Edit
Aparently lots of live servers have this turned on and index of /icons could be seen lots of places.
Open this file: %XAMPP_PATH%\apache\conf\extra\httpd-autoindex.conf
and change :
Alias /icons/ "X:/xampp/apache/icons/"
<Directory "X:/xampp/apache/icons/">
to this:
Alias /icons/ "./icons/"
<Directory "./icons/">
Restart your Apache Server.
I'd assume that you have an alias within your httpd.conf.
I'm not familiar with XAMPP's config files or their location (google suggests it's probably in \xampp\apache\conf\httpd.conf) but I'd suggest you're looking for a line like the following:
Alias /icons/ /usr/local/apache/icons/
See http://httpd.apache.org/docs/current/mod/mod_alias.html for more info.
EDIT:
According to XMAPP site, you need to check \xampp\apache\conf\httpd.conf and the extra subfolder.
I would look in either your apache config file (\xampp\apache\conf\httpd.conf) or your .htaccess files and see if there is a redirect going on.
EDIT: I think Grhm is correct in that an Alias is in your config file somewhere, per the XAMPP site:
The main configuration file for Apache. It's including other files from the subdirectory "extra".
See if there is a directory called extra in the \xampp\apache\conf\ directory and then go through the files in there and see if that Alias is present.
I have a domain, for example, http://example.com. It is already configured to point to
/var/www/
Basically, i want http://example.com to point to
/var/www/4.0/
and http://example.com/foobar/ to point to
/var/www/moo/
How can I do this with the httpd.conf file for Apache2? Thanks
Assuming you are only serving one domain (example.com), you can change your DocumentRoot to /var/www/4.0/
and set an Alias for the /foobar like
Alias /foobar /var/www/moo
If you are serving more than one domain from the same Apache, then you need to use the DocumentRoot within a VirtualHost tag.
More info is here: http://httpd.apache.org/docs/2.2/vhosts/
I think you're going about this the wrong way with httpd.conf, but I'll answer your question as you asked it first and then explain about that.
There are two settings in httpd.conf relevant to this.
The DocumentRoot setting is the important one, it configures the base directory from which to serve. Change it as so:
Before:
DocumentRoot "/var/www"
After:
DocumentRoot "/var/www/4.0"
Be sure not to use any / after the 4.0, it's not needed.
A little under 30 lines below this setting is another, which should say:
As the comment above it says, change it to "/var/www/4.0" too.
This would set www.example.com to the 4.0 directory (first part) and apply the relevant settings to this directory too (second part).
But I don't think you should do that, setting apache to serve the 4.0/ directory with httpd.conf makes a mess for serving the other directories. I'd suggest you read about redirects and how to implement them with whatever language you're using. Then you can point one URL to another without it ever being noticed in the browser (unless they're really trying to).
So without changing DocumentRoot from "/var/www", you can edit /var/www/index.php (or whatever) and have it redirect to /var/www/4.0/. The same can be done in /var/www/foobar/index.php to display /var/www/moo/ instead, but here I'd really just rename the "foobar" directory on the server to "moo". If you want to get elaborate, look into mod_rewrite, but I'd advise you to try all your alternatives first and only use it if you really need to, it's quite a complex tool.