Easy methods to override content material kind with Nginx internet server


Get real time updates directly on you device, subscribe now.

I configured Nginx server. Nevertheless, it’s sending the flawed content material kind. I must power Nginx to ship particular “Content material-Kind: textual content/xml; charset=UTF-Eight“. How do I configure Nginx to override content material kind for given URL location?

Introduction – MIME is an acronym for Multipurpose Web Mail Extensions (MIME). It’s a customary that signifies the character and format of a doc, file, or assortment of bytes. All internet browsers use the MIME kind to find out how one can course of a URL. Therefore, it’s important that Nginx ship the proper MIME kind within the response’s Content material-Kind header.

Easy methods to see Content material-Kind header

Use the next curl command:
curl -I url
curl -I curl -I https://www.linuxadminqa.com/wp-content/uploads/2019/01/how-to-override-content-type-with-nginx-web-server.gif
Pattern outputs:

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


The content-type: picture/gif signifies that picture and subtype is gif picture.

Easy methods to discover out default mine varieties in Nginx

Search for config file named mime.varieties inside nginx config listing:
# discover /and many others/nginx -name mime.varieties
Use cat command or vi command to view mime.varieties file:
vi /and many others/nginx/mime.varieties
View and force nginx to send specific Content-Type

Override content material kind with Nginx internet server

Say once I request atom.xml file, there’s
content-type: textual content/xml
And I need it to be appropriate one as follows:
Content material-Kind: content-type: textual content/html; charset=UTF-Eight
Once more, I used curl command:
curl -I https://www.cyberciti.biz/atom/atom.xml
How to override content type with Nginx on Linux
To repair this replace your mime.varieties file:
# vi /and many others/nginx/mime.varieties
And ensure following config exists:
utility/atom+xml atom;
Save and shut the file. Reload/restart the Nginx service. For instance, GNU/Linux consumer can run:
# systemctl reload nginx

Easy methods to power Nginx to ship particular Content material-Kind

Another choice is so as to add the next on to config file:

utility/atom+xml atom xml;

Nginx override content material kind for URL

Additionally it is potential to override content material kind for given URL sample. For instance, I edited /and many others/nginx/domains/cyberciti.biz/default.conf and added the next in server context:

### power utf-Eight and content material kind, good bots for web optimization ##
location = /atom/atom.xml

Save and shut the file. Restart or reload nginx server:
# service nginx reload
Check it:
curl -I https://www.cyberciti.biz/atom/atom.xml
nginx overwrite header and content-type


This web page demonstrated how one can overwrite default Content material-Kind in nginx. I strongly recommend that you just learn this web page right here and right here for extra info.

Posted by: Vivek Gite

The writer is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a coach for the Linux working system/Unix shell scripting. Get the newest tutorials on SysAdmin, Linux/Unix and open supply subjects through RSS/XML feed or weekly e mail e-newsletter.

Source link

Leave A Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More