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

หลังจากที่ไม่ได้จับ NGINX มาสักพัก มัวแต่ไปนั่งเล่นอย่างอื่นอยู่ แต่พอดีว่าช่วงนี้งานเข้า NGINX รัว ๆ ก็เลยต้อง setup ระบบไว้เตรียมบรรยาย ... แต่มาคราวนี้รู้สึกขี้เกียจ ไม่อยากทำอะไรยุ่งยาก เก็บพลังงานไว้ดีกว่า ... ด้วยความที่เพิ่งไปสอน Ansible มา เห็นว่า NGINX ทำ collection ใหม่ไว้หลายอย่างเลย ลองแวะไปดูให้ละเอียด ... มี Ansible playbook สำหรับติดตั้ง NGINX นินา ก็เลยบันทึกประสบการณ์แบบขี้เกียจ ๆ มาให้ลองอ่านดูครับ
สิ่งที่ต้องเตรียม
  • server Ubuntu Server 20.04.2 LTS
  • ติดตั้ง 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
    แก้ไข deploy-nginx.yml
    $ cd ansible-collection-nginx/playbooks/
    $ vi deploy-nginx.yml
    ---
    - hosts: all
      become: yes
      become_user: root
      become_method: sudo
      connection: local
      collections:
        - nginxinc.nginx_core
      roles:
        - role: nginx
    เรียกใช้งาน ansible playbook เพื่อติดตั้ง NGINX
    $ ansible-playbook -i "localhost, " deploy-nginx.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 Open Source"
    }
    [...]
    TASK [nginx : Debug NGINX output] **************************************************************************************************************************
    skipping: [localhost]
    
    TASK [nginx : Configure logrotate for NGINX] ***************************************************************************************************************
    skipping: [localhost]
    
    TASK [nginx : Install NGINX Amplify] ***********************************************************************************************************************
    skipping: [localhost]
    
    PLAY RECAP *************************************************************************************************************************************************
    localhost                  : ok=14   changed=5    unreachable=0    failed=0    skipped=22   rescued=0    ignored=0
    ทดสอบการทำงานของ NGINX
    $ 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>
    มูลค่าความสุข

    29

    This website collects cookies to deliver better user experience

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