To edit MIME types in Apache and Nginx, you must modify their respective configuration files to map specific file extensions to the correct IANA registered MIME media types. Web servers use these mappings to send the mandatory Content-Type header, informing browsers how to render files (e.g., displaying an image vs. downloading a file). 🛡️ Pre-requisite Rules Before Editing
Always back up your original configuration files before making edits.
Test your configuration syntax before restarting the web server to prevent breaking the live website. 🚂 How to Edit MIME Types in Apache
Apache handles MIME types using the mod_mime module. You can edit mappings globally via the main configuration file or per-directory via an .htaccess file. Method 1: Global Configuration (httpd.conf / apache2.conf)
File Location: Typically found at /etc/httpd/conf/httpd.conf (CentOS/RHEL) or /etc/apache2/apache2.conf (Ubuntu/Debian).
Step 1: Open the file with administrative privileges (e.g., sudo nano /etc/apache2/apache2.conf).
Step 2: Add the AddType directive at the bottom of the file or inside a block: AddType application/json .json AddType video/mp4 .mp4 Use code with caution. Step 3: Save the file and close it. Method 2: Per-Directory Configuration (.htaccess)
If you do not have root server access, you can add mappings locally.
Step 1: Create or open the .htaccess file in your website’s document root directory. Step 2: Add the AddType lines exactly as shown above. Step 4: Test and Restart Apache Test configuration: sudo apachectl configtest Reload or restart to apply changes: sudo systemctl reload apache2 Use code with caution. ⚡ How to Edit MIME Types in Nginx
Unlike Apache, Nginx does not use .htaccess files. All configuration must be performed inside the central configuration directories. Method 1: Edit the Central mime.types File (Recommended)
Nginx utilizes a structured file that houses all default MIME definitions. nginx how to override/add single mime-type
Leave a Reply