Reputation: 1793
I have linux server (Red Hat Enterprise Linux Server release 5.3 (Tikanga)) with apache installed. It is already used for browsing some documents. Now I would like to add a new Directory (with a html page), so whenever the directory is browsed it can display the html page.
But I am not sure of where all to edit the httpd.conf file
Existing httpd.conf:
When I hit the url "http://servername/eng" it displays list of folders.
Now, I want to add a website to this existing, so when user hit the url "http://servername/builds" it should display a html page in the browser.I have added my "index.html" page in location "/var/www/html/builds/"
For this I added the below code to httpd.conf file
Please let me know what all modifications are required in the conf file
Upvotes: 1
Views: 6748
Reputation: 14831
You can do it in a few different ways.
Putting index.html
in /build
This requires you to have this setting:
DirectoryIndex index.html
(it should be there by default on most platform.)
Also for this to work, rather than putting new <Directory>
, you should put the build/
directory in the directory that holds your http://example.com/
files. For instance:
/var/www/example.com/public_html/eng/
/var/www/example.com/public_html/builds/
/var/www/example.com/public_html/builds/index.html
Storing build/
in folder completely unrelated to example.com
, but still be able to reach it via example.com/builds
For this, you need to rewrite the URLs so that example.com/builds
redirects the user to the final URL. This is most easily achieved through mod_rewrite. You enable mod_rewrite
module in your Apache's configuration, make sure that example.com
can have .htaccess
files through ensuring proper AllowOverride
entry in example.com
's <Directory>
configuration, create /var/www//example.com/public_html/.htaccess
(or similar) file, and fill it RewriteEngine On
and RewriteRule
s you need. More on mod_rewrite in the Internet and in the documentation.
Completely separate virtual server, for example builds.example.com/
In this case, what you're looking for are virtual servers. These are not defined in httpd.conf
or configuration itself, but usually have dedicated directory.
For example, to add builds.example.com
that works for port 80, you'd need to create following entry:
<VirtualHost *:80>
ServerName builds.example.com
DocumentRoot /var/www/builds.example.com/public_html/
</VirtualHost>
Where to put this? Well, it depends on the platform. For Debian, you put this in a new file in /etc/apache2/sites-available/
, e.g. /etc/apache2/sites-available/example.com
, and symlink to it in /etc/apache2/sites-available
(on Debian, you can do this easily with a2ensite <NAME_OF_FILE>
. On your platform this procedure might be different, so look it up ("adding virtual servers on " would be a start). After adding virtual servers, you need to reload your Apache configuration.
Please let me know if this satisfies your question, if not, I'll edit the answer accordingly.
Upvotes: 2