การติดตั้งและตั้งค่า Nginx
เรียนรู้วิธีติดตั้ง Nginx บนระบบปฏิบัติการต่าง ๆ และดำเนินการตั้งค่าเบื้องต้น
การติดตั้งและตั้งค่า Nginx เป็นบทเรียน API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Get Ready to Install Nginx
Welcome! In this lesson, we'll get Nginx up and running on your system. Nginx (pronounced "engine-x") is a powerful web server and reverse proxy that's widely used for high-performance applications.
We'll cover installation on common operating systems and explore its initial setup.
Installing on Linux (APT)
For Debian or Ubuntu Linux, Nginx is readily available through the APT package manager. These commands will update your package list and install Nginx:
sudo apt updatesudo apt install nginx
The sudo command grants administrative privileges, necessary for system-wide changes.
sudo apt update
sudo apt install nginxCheck Nginx is Running
After installation, Nginx usually starts automatically. You can verify its status using systemctl, a command for controlling system services.
A successful output will show "active (running)". Try running this:
sudo systemctl status nginxManaging Nginx Service
Knowing how to control the Nginx service is crucial. Here are the most common commands you'll use:
- Start:
sudo systemctl start nginx - Stop:
sudo systemctl stop nginx - Restart:
sudo systemctl restart nginx(stops and then starts) - Reload:
sudo systemctl reload nginx(applies config changes without dropping connections)
Where to Find Configs
Nginx configurations live in specific directories. On Linux systems, the main configuration file is usually located at /etc/nginx/nginx.conf.
This main file often includes other configuration files from the /etc/nginx/sites-available/ directory. These are then symlinked (a type of shortcut) to /etc/nginx/sites-enabled/ to activate them.
Your First Nginx Page
Once Nginx is running, open your web browser and navigate to http://localhost/ or your server's IP address. You should see a default "Welcome to Nginx!" page.
This page confirms Nginx is serving content correctly from its default web root, which is typically /var/www/html.
How Nginx Listens
By default, Nginx listens for incoming web requests on port 80 (the standard HTTP port). This is configured in the nginx.conf file or included server blocks.
You can verify which ports Nginx is listening on using the ss command (Socket Statistics). Try running this example:
sudo ss -ltn | grep 80Installation on macOS
For macOS users, Homebrew is the easiest way to install Nginx. Homebrew is a popular package manager for macOS.
First, ensure Homebrew is installed. Then, use the brew command to install Nginx and start its service:
brew install nginx
brew services start nginxInstallation Check
Let's test your understanding of basic Nginx service commands.
Recap: Nginx is Installed!
Great job! You've successfully learned how to install Nginx on both Linux and macOS, verify its status, and manage the service with basic commands.
We also touched upon where Nginx stores its configuration files and how to confirm it's serving the default page. In the next lesson, we'll dive into the basic Nginx configuration file structure!
คำถามที่พบบ่อย
บทเรียน “การติดตั้งและตั้งค่า Nginx” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การติดตั้งและตั้งค่า Nginx” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การติดตั้งและตั้งค่า Nginx”
เรียนรู้วิธีติดตั้ง Nginx บนระบบปฏิบัติการต่าง ๆ และดำเนินการตั้งค่าเบื้องต้น คุณปฏิบัติ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “การติดตั้งและตั้งค่า Nginx” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) นี้ได้ไหม
ได้ บทเรียน API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การติดตั้งและตั้งค่า Nginx
- การตั้งค่า Nginx เบื้องต้น
- การให้บริการเนื้อหาแบบคงที่ด้วย Nginx
- บล็อก Location ของ Nginx และการจับคู่คำขอ