- Install
- Useful Command
- Directives
- Nginx Site
- Location
- Reverse Proxy
- Load Balance
- Caching
- No Cache
- Cache Set Expries
- Proxy Cache
- Micro Caching
- Ratelimit
- SSL
- Self Signed
- Letsencrypt
- Certbot
- Websocket
- Modules
- WAF
- Lua
- Openresty
- Monitoring
$ sudo apt update && sudo apt dist-upgrade && sudo apt autoremove
$ cd /tmp/ && wget http://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key
$ sudo sh -c "echo 'deb http://nginx.org/packages/mainline/ubuntu/ '$(lsb_release -cs)' nginx' > /etc/apt/sources.list.d/nginx.list"
$ sudo apt update
$ sudo apt install nginx
$ nginx -s stop # หยุดการทำงาน nginx
$ nginx -s reload # ใช้เมื่อมีการแก้ไข config ของ nginx
$ nginx -t # ตรวจสอบค่า config nginx ก่อนสั่ง reload
$ service nginx start|stop|restart # สั่งงาน nginx ผ่าน service
ยกตัวอย่างแค่ http, server, upstream
===== http ================================
Syntax: http { ... } # ตัวอย่างการประกาศใช้งาน
Default: — # ไม่มีการกำหนดค่า default
Context: main # เป็น main directive ไม่อยู่ภายใต้ใคร
===== server ==============================
Syntax: server { ... } # ตัวอย่างการประกาศใช้งาน
Default: — # ไม่มีการกำหนดค่า default
Context: http # อยู่ภายใต้ http เช่น http { server { ... } }
===== upstream ============================
Syntax: upstream name { ... } # ตัวอย่างการประกาศใช้งาน
Default: — # ไม่มีการกำหนดค่า default
Context: http # อยู่ภายใต้ http เช่น http { upstream name { ... } }
https://github.com/yuttasakcom/nginx-sample/tree/master/01.site
$ docker-compose up -d
$ curl localhost -H 'Host: example.com'
===== output =====
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Nginx Site</title>
</head>
<body>
<p>example.com</p>
</body>
- ควรแยก config site แต่ละ site เป็น 1 config file เก็บไว้ใน conf/site/
- แก้ไข nginx.conf จาก include /etc/nginx/conf.d/*.conf; เป็น include conf/site/*;