How to override content type with Nginx web server

I configured Nginx server. However, it is sending the wrong content type. I need to force Nginx to send specific “Content-Type: text/xml; charset=UTF-8“. How do I configure Nginx to override content type for given URL location?

Introduction – MIME is an acronym for Multipurpose Internet Mail Extensions (MIME). It is a standard that indicates the nature and format of a document, file, or assortment of bytes. All web browsers use the MIME type to determine how to process a URL. Hence, it is essential that Nginx send the correct MIME type in the response’s Content-Type header.

How to see Content-Type header

Use the following curl command:
curl -I url
curl -I curl -I

Sample outputs:

HTTP/2 200 
date: Mon, 21 Jan 2019 12:07:22 GMT
content-type: image/gif
content-length: 377
cache-control: max-age=315360000

The content-type: image/gif indicates that image and subtype is gif image.

How to find out default mine types in Nginx

Look for config file named mime.types inside nginx config directory:
# find /etc/nginx -name mime.types
Use cat command or vi command to view mime.types file:
vi /etc/nginx/mime.types

Override content type with Nginx web server

Say when I request atom.xml file, there is
content-type: text/xml
And I want it to be correct one as follows:
Content-Type: content-type: text/html; charset=UTF-8
Again, I used curl command:
curl -I

To fix this update your mime.types file:
# vi /etc/nginx/mime.types
And make sure following config exists:
application/atom+xml atom;
Save and close the file. Reload/restart the Nginx service. For example, GNU/Linux user can run:
# systemctl reload nginx

How to force Nginx to send specific Content-Type

Another option is to add the following directly to config file:

types {
    application/atom+xml    atom xml;

Nginx override content type for URL

It is also possible to override content type for given URL pattern. For example, I edited /etc/nginx/domains/ and added the following in server context:

    ### force utf-8 and content type, good bots for SEO ##
    location = /atom/atom.xml {
        ## override content-type ##
        types { } default_type "application/atom+xml; charset=utf-8";
        ## override header (more like send custom header using nginx) #
        add_header x-robots-tag "noindex, follow";

Save and close the file. Restart or reload nginx server:
# service nginx reload
Test it:
curl -I


This page demonstrated how to overwrite default Content-Type in nginx. I strongly suggest that you read this page here and here for more information.

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @