Apache2 httpd.conf help - apache

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.

Related

Redirect to another server site without changing domain name

I have two servers running Apache2, one with an associated domain name, let's say "www.home.com" and another one only known by its IP address, let's say 10.11.12.13.
On www.home.com I have three web sites, configured through aliases in apache.
I have http://www.home.com, http://www.home.com/school, http://www.home.com/work.
All these sites are on the server www.home.com.
On 10.11.12.13, I have only one site, accessible by http://10.11.12.13/wiki
How can I configure apache to have http://www.home.com/wiki working but transparently (not changing URL) call http://10.11.12.13/wiki site ?
In other words, the user shall only see www.home.com/wiki/xxxxx when he uses the wiki.
What I have done:
On www.home.com : i have added a wiki folder with nothing in it, and an alias for www.home.com/wiki to work properly.
Then I have tried to use mod rewrite to replace 10.11.12.13 by www.home.com but that does not work, and I am not even sure to do it the right way.
For your information, mod rewrite is configured and works properly on both servers.
Someone could please help me on that ?
Maybe mod rewrite is not the right solution ?
Thanks !
Sam
I finally found a solution : the mod_proxy along with tags.
The conf that worked for me:
<VirtualHost *:80>
[...]
ServerName www.home.com
<Location /wiki>
Allow from all
ProxyPass "http://10.11.12.13/wiki"
ProxyPassReverse "http://10.11.12.13/wiki"
</Location>
</VirtualHost>

Apache Reverse Proxy Sending Browser to Backend Directly Instead

(UPDATE at the bottom for the main question, below may be superfluous details)
I'm having an interesting problem with Apache not reverse proxying as expected.
Basically, what's happening is when I click a link on my website that goes to the relative path /app1, I am expecting it the URL to be external.company.ca/app1 with content coming from internal.company.ca/some_app. Instead, the browser is going directly to internal.company.ca/some_app.
No 302 or anything, just straight there. This is odd to me, since internal.company.ca is not mentioned anywhere in the configuration except for the reverse proxy config, so I don't know how the browser is learning of the domain at all.
Here is a Fiddler capture from the client (browser) point of view showing the behaviour right after I click the link that goes to /app1 (you'll have to trust me that the green names are external.company.ca and the black names are internal.company.com and the path is /some_app/blahblah):
Everything happening after this point is loading the page with internal.company.com. This won't work at all in production, of course.
The following is a (truncated) version of our Apache configuration files for consideration:
<VirtualHost *:80>
# rewrite rules to 443
</VirtualHost>
<VirtualHost *:443>
ServerName external.company.ca
ServerAlias external.company.com
# Logging rules.........
SSLEngine on
SSLProxyEngine on
SSLProxyVerify none
# Most of this is off for testing purposes, adding in case it matters
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
# more SSL stuff.... Now on to the interesting part
ProxyPreserveHost On
ProxyPass /app1 https://internal.company.com/some_app
ProxyPassReverse /app1 https://internal.company.com/some_app
</VirtualHost>
At one point, I thought that possibly the cookies were throwing things off since they were under different domains (.ca in front, .com in back), but I believe if the reverse proxying was working correctly, the browser would be none the wiser. Anyone see anything wrong with the above?
UPDATE
I found the culprit:
<script type="text/javascript">window.location.assign('https://internal.company.com/app1/login?redirectUrl=' + encodeURIComponent(window.location.pathname + window.location.hash));</script>
The problem is, how do I rewrite this absolute URL using Apache? I know mod_proxy_html modifies element attributes (such as href in the a element) but can it rewrite arbitrary data in an element itself?
The internal application was provided by a vendor, and although it may be possible to make modifications to it to remove code like the above, I would prefer to stay away from that path for now to see if there are alternatives.
I've come up with a somewhat nasty work-around:
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLLinks script src
ProxyHTMLURLMap https://internal.company.com
The problem is the use of absolute URL's throughout the HTML (and javascript) coming from the vendor's app. A search and removal of the domain solves the problem (but is incredibly slow).
If anyone has this problem in the future, I do not recommend using this solution. I'm guessing you're here because you can't modify the internal application. You should instead be sending in a ticket to whoever maintains the code to make their application more reverse-proxy friendly.
A potentially safer solution would be the use of mod_substitute. You could also consider ProxyHTMLExtended, but it can be quite brutal in its replacements, occasionally breaking JavaScript here and there.
Edit: Just noticed you're currently using ProxyHTMLExtended. My bad. As you've highlighted it is a pretty brutal and dangerous solution to the problem.

Subdomains not working on 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.

Apache always get 403 permisson after changing DocumentRoot

I'm just a newbie for Apache. I just installed apache 2.2 on the FreeBSD box at my home office. The instruction on FreeBSD documentation is that I can change the DocumentRoot directive in order to use the customized directory data. Therefore, I replaced...
/usr/local/www/apache22/data
with
/usr/home/some_user/public_html
but something is not right. There's index.html file inside the directory, but it seems that apache could not read the directory/file.
Forbidden
You don't have permission to access / on this server.
The permission of
public_html
is
drwxr-xr-x
I wonder what could be wrong here. Also, in my case, I am not going to host more than one website for this FreeBSD box, so I didn't look at using VirtualHost at all. Is this a good practice just to change the DirectoryRoot directive?
Somewhere in the apache config is a line like:
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/usr/local/www/apache22/data">
You must change this path too, to make it work. This directive contains for example:
Order allow,deny
Allow from all
Which give initial user access to the directory.
one possibility that comes to mind is SELinux blocking web process from accessing that folder. If this is the case, you would see it in selinux log. You would have to check the context for your original web root with:
ls -Zl
and then apply it to your new web folder:
chcon whatevercontextyousaw public_html
Or, instead, if its not a production server that requires security (like a development machine behind a firewall), you might want to just turn selinux off.
Just one idea. Could be a number of other things.

Apache virtual directory without redirect

What I'm trying to accomplish is pulling content from a directory that is not the same as the url path. For example:
URL: example.com/
path: /www/production/
Currently, the root url pulls content from the path above. What I want to do is something like this:
URL: example.com/
path: /www/production/root/
So the base URL "example.com" should pull data not from /www/production/ but from /www/production/root/.
I think this is called a Virtual Directory in IIS. Is there something like this in Apache?
Edit for clarification:
I have a ton of existing content that I do not want to have to restructure yet. However, the root site is being completely rebuilt and is going to be quite a bit bigger. What I want is each microsite to have it's own directory, such that requests for example.com/ should pull content from /www/production/root/ while requests for example.com/microsite/ should still pull content from /www/production/microsite/.
Hopefully that makes more sense. :)
Its not exactly clear what your problem is. If you just want all URLs to be taken relative to some location on the server, then you can use the DocumentRoot directive:
DocumentRoot /www/production/root/
If you want to only have certain urls go to the new place, then you can either use the Alias or AliasMatch directives from the mod_alias module. These can map either prefixes on a URL, or url Regexes to other server locations. If even this isn't sufficient, you can use mod_rewrite which allows for arbitrary chains of url rewriting, but can get very hairy to maintain, so you're better off avoiding that module if you can.
http://httpd.apache.org/docs/2.0/mod/mod_alias.html
If I understand your question correctly, then the following, in your VirtualHost config, does what you're asking for:
ServerName example.com
DocumentRoot /www/production/root/