Apache http.conf - Route Requests to URL Directory Using Alias - apache

I have a web application that I would like to be accessed in the following format:
52.1.2.3/myapplication
I currently have a httpd.conf that looks like
<VirtualHost *:80>
DocumentRoot /var/www/myapp/public_html
ServerName 52.1.2.3
ServerAlias 52.1.2.3
Alias /myapplication /var/www/myapp/public_html
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I got to the URL 52.1.2.3/myapplication, I want Apache to load the application stored in /var/www/myapp/public_html.
If I take out the Alias /myapplication /var/www/mya/pp/public_html configuration from the above, I can reach my web application by going to 52.1.2.3. But when I try to go to 52.1.2.3/myapp with the Alias option added in, I get a 403 Forbidden response.
How would you bind 52.1.2.3/myapplication to /var/www/myapp/public_html?

in my understanding you have to add the same path to the directory which you have used for the alias.
So,your path for alias /myapplication is /var/www/myapp/public_html.So put the same in below directory :
<Directory /var/www/myapp/public_html>
Options +Indexes +FollowSymLinks +MultiViews
Order allow,deny
Allow from all
</Directory>

Related

Configure Apache2 to automatically append default file extention to a URL when one is not given

How do I configure Apache2 to load a page with the extensions of default files provided when a page is requested without an extension.
So for example I want http://webpage.com/page to automatically load either:
http://webpage.com/page.html OR
http://webpage.com/page.php
NOTE: I don't want any redirection or URL renaming to occur; meaning I want the address bar to still be showing http://webpage.com/page
Per CBroe's comments and his reference to apache docs httpd.apache.org/docs/2.2/content-negotiation.html#multiviews - Adding Multiviews to Options directive inside a Directory section solves this issue.
You can either add it to a Directory section like below (to affect all web applications under sites directory)
<Directory /sites>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
-OR- inside a site host definition
<VirtualHost *:80> #site.dev
ServerAdmin admin#email.com
ServerName site.dev
ServerAlias site.dev
DocumentRoot /sites/site.dev
<Directory /sites/site.dev>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

Two sites with Apache virtual hosts

I'm working on 2 different sites. I have local copies of them checked out from SVN at my home folder, and symbolic links in /var/www pointing to them.
I've set up virtual hosts in httpd.conf like this:
<VirtualHost *:80>
DocumentRoot /var/www/siteA
ServerName 192.168.0.10/siteA
<Directory "/var/www/siteA">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/siteB
ServerName 192.168.0.10/siteB
<Directory "/var/www/siteB">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I would like to be able to access the sites with 192.168.0.10/siteA and /siteB, but when typing the address in browser, it throws a 404 and apache error log says: "File does not exist: /var/www/siteA/siteA".
What am I doing wrong and where does the second "/siteA" come from?
You've got too much configuration in there. /SiteA and /SiteB should be paths relative to your site root, you can't have different sites on the same host header, which in this case is "192.168.0.10". If you want to bind that address to the configuration, something along the lines of the following should work.
<VirtualHost 192.168.0.10:80>
DocumentRoot /var/www
ServerName 192.168.0.10
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you now browse to /SiteA, /SiteB you should see the contents of your directory as long as your symlinks are correct. You also need to ensure you have the "NameVirtualHost" directive set correctly in your httpd.conf.

Redirect to a subfolder in Apache virtual host file

I have Joomla installed on a webserver running Ubuntu Server 12.04. The Joomla folder is located at /var/www/cms/.
My vhost file at /etc/apache2/sites-enabled/default has the following content:
<VirtualHost *:80>
ServerName domain.com/
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName domain.com:443
DocumentRoot /var/www/cms
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/cms>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
(...)
</VirtualHost>
At the moment, all the requests to domain.com and anything entered after that like domain.com/example gets directed and processed by Joomla which either redirects to a proper page or returns a custom 404 error. This all works.
Now, I would like to filter all the requests that go to domain.com/subfolder before they get processed by Joomla and redirect them to /var/www/subfolder (instead of my root folder at /var/www/cms/).
I believe the file in /etc/apache2/sites-enabled/default (seen above) is the right place to define such a redirect, however I have not been able to figure out at what position and how to achieve this.
You should add to your configuration:
Alias /subfolder /var/www/subfolder
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
and fit the configuration between "Directory" to your needs.
See the Apache documentation to have more informations.

Symfony 1.4 under a userdir in Apache

I have users who want to run their own Symfony projects under their home directories, but I can't get Symfony to work properly. In my Apache2 config file, I set the userdir as:
UserDir sfproject/web
But the DocumentRoot has to be:
/var/www/sfproject/web
This requirement is there because when we deploy the code to production, we don't want to change the Apache config file. And everything is going to be under that directory.
The problem is that when we go to a user directory: dev.server.com/~asdf
Symfony gives a 404 error: Empty module and/or action after parsing the URL "/index.php" (/).
I don't understand what's wrong. We want them to see their individual projects in their home directories. I looked at some other people setting up Symfony in shared hosting environments, but this is not a shared hosting environment. This is a dedicated server and I have root. Thank you for your help. Here is the relevant parts of my Apache config:
UserDir sfproject/web
<Directory "/usr/share/php/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
<VirtualHost *>
DocumentRoot "/var/www/sfproject/web"
DirectoryIndex index.php
<Directory "/var/www/sfproject/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /usr/share/php/data/symfony/web/sf
<Directory "/usr/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I think something like the following would be closer to a solution.
<VirtualHost *>
DocumentRoot "/var/www/sfproject/web"
DirectoryIndex index.php
<Directory "/var/www/sfproject/web">
AllowOverride All
Allow from All
</Directory>
# or is the dir /usr/share/php/data/symfony/data/web/sf ?
Alias /sf /usr/share/php/data/symfony/lib/vendor/symfony/data/web/sf
<Directory "/usr/share/php/data/symfony/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
The paths from your excerpt does not look good I guess. Try it out and let us know if it works.

Moveable type images not displayed

I installed Moveable type on a ubuntu box.
The admin section works great.
However the front page does not. The images and CSS are not displayed.
This is coming from the apache error log:
Permission denied: exec of '/var/www/mt/example/styles.css' failed
Premature end of script headers: styles.css
I think it's related to my apache config. Since i call the admin section using the localhost, but i use the example.com for the front page, which is the part that doesnt work.
This is my apache config:
NameVirtualHost *
<VirtualHost *>
ServerAdmin chris#example.com
ServerName mt.example.net
DocumentRoot /var/www/mt
Alias /mt-static /var/www/mt/mt-static
<Directory /var/www/mt/mt-static>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias / /var/www/mt/
<Directory /var/www/mt>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
ServerAdmin chris#example.com
ServerName example.com
ServerAlias example.com www. example.com
DocumentRoot /var/www/example
Alias /mt-static /var/www/mt/mt-static
<Directory /var/www/mt/mt-static>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Redirect /mt.cgi http://mt.example.net/mt.cgi
</VirtualHost>
it because the directory where the css file is located (var/www/mt/example/) is a sub-directory of one which is declared to be a script in (/var/www/mt) with Options +ExecCGI
Directories inherit the options of their parents
It sounds like Apache has tried to run the .css file as an executable. The only thing which I can suggest is that you might have a css file which has an executable permission, for some reason, so Apache tries to execute it. Try
chmod a-x
on the CSS file and see if it makes a difference.
Sometimes files copied from Windows have executable set when they shouldn't.