how to set utf-8 character encoding in apache http file server

Post Reply
djemos
Site Admin
Posts: 676
Joined: 15 Apr 2016 06:03

how to set utf-8 character encoding in apache http file server

Post by djemos »

A http file server is used to serve files which users can only read online or download. If a file name is in Greek language then user see strange characters. In web server utf-8 is set using html headers. But what we can do for the file server?

To solve this problem we have to do the following. Keep in mind that using the same ip address can have a http web server and also a http file server using virtual hosts.
So in slackware lets say that our web server is under /var/www/htdocs/forum folder and our http file server under /var/www/htdocs/pub folder.
I suppose that in /etc/httpd/httpd.conf file have un-comment the lines
LoadModule vhost_alias_module lib64/httpd/modules/mod_vhost_alias.so
Include /etc/httpd/extra/httpd-vhosts.conf

1. We create a .htaccess file in /var/www/htdocs/pub/ folder where we put the following lines in it.

Code: Select all

IndexOptions +Charset=UTF-8
Options +Indexes +Includes +FollowSymLinks +MultiViews
2. Set our virtual hosts in /etc/httpd/extra/httpd-vhosts.conf file where we have to add AllowOverride All between lines serve the http file server. See bellow. The http web server ariadni.noip.me and http file server slackel.ddns.net have the same dynamic ip.
“AllowOverride” allows you to override some Apache settings.

Code: Select all

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
	ServerName ariadni.noip.me
	DocumentRoot "/var/www/htdocs/forum"
    <Directory "/var/www/htdocs/forum/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride None
		Require all granted
   </Directory>  
</VirtualHost>

<VirtualHost *:80>
    ServerName slackel.ddns.net
    DocumentRoot "/var/www/htdocs/pub"
	<Directory "/var/www/htdocs/pub/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews 
		AllowOverride All
		Require all granted
   </Directory>
3. Restart apache server

Code: Select all

sudo service restart httpd
or

Code: Select all

sudo sh /etc/rc.d/rc.httpd restart
See here http://ariadni.noip.me the web server
http://slackel.ddns.net/LOGO_linux/logo ... ΗΝΙΚΑ-8.x/ the file server with Greek named files.
Post Reply