<commit_before>---
title: Update Nginx version on AMI Linux
summary: Let's update the Nginx version on AMI Linux in few steps. I'll show you how to do it, crash the server and fix it back. 
categories: devops
tags: nginx ami linux update
date: 2021-12-07 09:09:09 +0000
cover: https://cdn.pixabay.com/photo/2013/11/15/13/57/road-210913_1280.jpg
layout: post
---

Today I decided to show you how to update Nginx version on AMI Linux


## Check current version

```sh
$ nginx -v
nginx version: nginx/1.16.1
```

## Update nginx

```sh
$ sudo yum update nginx
```

Then I said oo good that is all, let's restart nginx and see if it works:


```sh
$ sudo service nginx restart
```

What is the result for me: 

```sh
$ sudo service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-12-07 12:17:05 UTC; 4s ago
  Process: 23112 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
  Process: 23110 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 3121 (code=killed, signal=KILL)
   CGroup: /system.slice/nginx.service
           ├─9155 nginx: worker process is shutting down
           └─9156 nginx: worker process is shutting down

Dec 07 12:17:04 systemd[1]: Unit nginx.service entered failed state.
Dec 07 12:17:04 systemd[1]: nginx.service failed.
Dec 07 12:17:04 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 07 12:17:05 nginx[23112]: nginx: [emerg] module "/usr/lib64/nginx/modules/ngx_http_image_filter_module.so" version 1016001 instead of 1020001 in ...lter.conf:1
Dec 07 12:17:05 nginx[23112]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 07 12:17:05 systemd[1]: nginx.service: control process exited, code=exited status=1
Dec 07 12:17:05 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Dec 07 12:17:05 systemd[1]: Unit nginx.service entered failed state.
Dec 07 12:17:05 systemd[1]: nginx.service failed.
```

And I said ooou this is great :D, let's fix it:

```sh
sudo yum remove nginx-mod*
sudo yum install nginx-module-*
```

Now let's try again to restart the nginx

```sh
$ sudo service nginx restart
```

And here is the result, this time all good:

```sh
$ sudo service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-12-07 12:22:01 UTC; 5min ago
  Process: 23409 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 23407 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 23405 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 23411 (nginx)
   CGroup: /system.slice/nginx.service
           ├─ 9155 nginx: worker process is shutting down
           ├─ 9156 nginx: worker process is shutting down
           ├─23411 nginx: master process /usr/sbin/nginx
           ├─23412 nginx: worker process
           └─23413 nginx: worker process

Dec 07 12:22:01  systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 07 12:22:01  nginx[23407]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 07 12:22:01  nginx[23407]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 07 12:22:01  systemd[1]: Started The nginx HTTP and reverse proxy server.
```

Let's check the current version of nginx:

```sh
$ nginx -v
nginx version: nginx/1.20.1
```

Soo all is good! Have a nice day, fellow!

<hr>
<commit_msg>Update post<commit_after>---
title: Update Nginx version on AMI Linux
summary: Let's update the Nginx version on AMI Linux in few steps. I'll show you how to do it, crash the server and fix it back. 
categories: devops
tags: nginx ami linux update
date: 2021-12-07 09:09:09 +0000
cover: https://cdn.pixabay.com/photo/2013/11/15/13/57/road-210913_1280.jpg
layout: post
---

Today I decided to show you how to update Nginx version on AMI Linux


## Check current version

```sh
$ nginx -v
nginx version: nginx/1.16.1
```

## Update nginx

```sh
$ sudo yum update nginx
```

Then I said oo good that is all, let's restart nginx and see if it works:


```sh
$ sudo service nginx restart
```

What is the result for me: 

```sh
$ sudo service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-12-07 12:17:05 UTC; 4s ago
  Process: 23112 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
  Process: 23110 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 3121 (code=killed, signal=KILL)
   CGroup: /system.slice/nginx.service
           ├─9155 nginx: worker process is shutting down
           └─9156 nginx: worker process is shutting down

Dec 07 12:17:04 systemd[1]: Unit nginx.service entered failed state.
Dec 07 12:17:04 systemd[1]: nginx.service failed.
Dec 07 12:17:04 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 07 12:17:05 nginx[23112]: nginx: [emerg] module "/usr/lib64/nginx/modules/ngx_http_image_filter_module.so" version 1016001 instead of 1020001 in ...lter.conf:1
Dec 07 12:17:05 nginx[23112]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 07 12:17:05 systemd[1]: nginx.service: control process exited, code=exited status=1
Dec 07 12:17:05 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Dec 07 12:17:05 systemd[1]: Unit nginx.service entered failed state.
Dec 07 12:17:05 systemd[1]: nginx.service failed.
```

And I said ooou this is great :D, let's fix it:

```sh
sudo yum remove nginx-mod*
sudo yum install nginx-module-*
```

Now let's try again to restart the nginx

```sh
$ sudo service nginx restart
```

And here is the result, this time all good:

```sh
$ sudo service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-12-07 12:22:01 UTC; 5min ago
  Process: 23409 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 23407 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 23405 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 23411 (nginx)
   CGroup: /system.slice/nginx.service
           ├─ 9155 nginx: worker process is shutting down
           ├─ 9156 nginx: worker process is shutting down
           ├─23411 nginx: master process /usr/sbin/nginx
           ├─23412 nginx: worker process
           └─23413 nginx: worker process

Dec 07 12:22:01  systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 07 12:22:01  nginx[23407]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 07 12:22:01  nginx[23407]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 07 12:22:01  systemd[1]: Started The nginx HTTP and reverse proxy server.
```

Let's check the current version of nginx:

```sh
$ nginx -v
nginx version: nginx/1.20.1
```

## Update nginx to a specific version

Few hors later, after I release the post, I tried this on another server and surprise the latest version found was 1.20. In this case you can install a specific version for Nginx.

Go to <https://centos.pkgs.org/7/nginx-x86_64/nginx-1.20.1-1.el7.ngx.x86_64.rpm.html#download> and download the binary. If you want another version search above the package that you need.

```sh
wget https://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.1-1.el7.ngx.x86_64.rpm
```

Now in your folder the file `nginx-1.20.1-1.el7.ngx.x86_64.rpm` was downloaded, please install it as:

```sh
sudo rpm -Uvh nginx-1.20.1-1.el7.ngx.x86_64.rpm
sudo yum update nginx
```

Check Nginx version and don't forget to restart nginx service.

Soo all is good! Have a nice day, fellow!

<hr>

{'fraction_non_alphanumeric': 0.10902300927599085, 'fraction_numerical': 0.07842428623057462, 'mean_word_length': 3.9008264462809916, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3828043', 'n_tokens_mistral': 3447, 'n_tokens_neox': 2815, 'n_words': 1032}