How to combine nginx + Kestrel for production Part II: Fundamental Settings

Series:

 

1. Enable gzip compression

We tell nginx that it should compress certain files with gzip before sending them out. This gives us a huge performance gain!

Open the global setting file:

Move down and enable gzip by uncommenting and adding a few lines if necessary, e.g.:

(Note: if you don't want this to be a global setting, you can create a conf file in /etc/nginx/conf.d/)

 

2. Enable Browser Caching

We configure nnginx to set some meta information into certain headers, so the browser just need to download files when they've changed or are expired. Again, a huge performance gain!

Open your site config:

Setting up a cache :

Note: Go to /var/cache/nginx and see if there is a tmp folder. If not, create one!

Setting up rules:

(Save with Ctrl+O and Exit with Ctrl+X)

 

3. URL / IP Canonicalization

If the URL www.yourdomain.com and yourdomain.com and the server IP adress xxx.xxxx.xxx.xx don't resolve to the same URL, you will get double content. Not only you'll score worse in search engines, but in case of an attack you have to fight on 3 different fronts. It's quite simple to avoid that. In this case we redirect the other addresses to yourdomain.com

Open your site config:

Redirect the other server blocks to the main scheme:

 

4. Optional: Set a custom header

If you want to hide nginx in the response header (you should), you can overwrite it. Unfortunately the module is not distributed with the nginx source, so we need to install it first.

Install the ngx_headers_more module:

Open your site config:

Set your header:

 

5. Example file:

It lacks some stuff (e.g. ssl), but for the beginning .. not bad!

 

6. (Re)start nginx:

The changes we've made take place when we restart nginx.



Mahmut Jomaa is a Software Engineer from Germany.

Currently he attends university to gain more knowledge in Computer Science.


Security code Refresh