DEV Community

Damrongsak Reetanon
Damrongsak Reetanon

Posted on

ติดตั้ง NGINX Plus แบบขี้เกียจ

หลังจากที่ไม่ได้จับ NGINX มาสักพัก มัวแต่ไปนั่งเล่นอย่างอื่นอยู่ แต่พอดีว่าช่วงนี้งานเข้า NGINX รัว ๆ ก็เลยต้อง setup ระบบไว้เตรียมบรรยาย ... แต่มาคราวนี้รู้สึกขี้เกียจ ไม่อยากทำอะไรยุ่งยาก เก็บพลังงานไว้ดีกว่า ... ด้วยความที่เพิ่งไปสอน Ansible มา เห็นว่า NGINX ทำ collection ใหม่ไว้หลายอย่างเลย ลองแวะไปดูให้ละเอียด ... มี Ansible playbook สำหรับติดตั้ง NGINX Plus นินา ก็เลยบันทึกประสบการณ์แบบขี้เกียจ ๆ มาให้ลองอ่านดูครับ

สิ่งที่ต้องเตรียม

  • server Ubuntu Server 20.04.2 LTS
  • Key และ ​Certificate ที่เป็น Subscription ของ NGINX Plus เก็บที่ $HOME/nginx-repo.key และ $HOME/nginx-repo.crt

ติดตั้ง ansible และส่วนอื่น ๆ ที่จำเป็น

$ sudo apt -y update
$ sudo apt install -y ansible
$ ansible-galaxy collection install nginxinc.nginx_core
$ git clone https://github.com/nginxinc/ansible-collection-nginx.git
Enter fullscreen mode Exit fullscreen mode

แก้ไข deploy-nginx-plus.yml

$ cd ansible-collection-nginx/playbooks/
$ vi deploy-nginx-plus.yml
---
- hosts: all
  become: yes
  become_user: root
  become_method: sudo
  connection: local
  collections:
    - nginxinc.nginx_core
  roles:
    - role: nginx
      vars:
        nginx_type: plus
        nginx_license:
          certificate: /home/drs/nginx-repo.crt
          key: /home/drs/nginx-repo.key
Enter fullscreen mode Exit fullscreen mode

เรียกใช้งาน ansible playbook เพื่อติดตั้ง NGINX Plus

$ ansible-playbook -i "localhost, " deploy-nginx-plus.yml

PLAY [all] *****************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************
ok: [localhost]

TASK [nginx : Check whether you are using a supported NGINX distribution] **************************************
ok: [localhost] => {
    "changed": false,
    "msg": "Your OS, Ubuntu is supported by NGINX Plus"
}
[...]
TASK [nginx : Configure logrotate for NGINX] *******************************************************************
skipping: [localhost]

TASK [nginx : Install NGINX Amplify] ***************************************************************************
skipping: [localhost]

PLAY RECAP *****************************************************************************************************
localhost                  : ok=23   changed=11   unreachable=0    failed=0    skipped=22   rescued=0    ignored=0
Enter fullscreen mode Exit fullscreen mode

ทดสอบการทำงานของ NGINX Plus

$ curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
มูลค่าความสุข

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay