Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Nginx 反向代理 Apache 极简配置:81 端口測試、語法檢查、reload 生效、Response Header 驗證

編輯:Linux 教學

場景:原站點跑 Apache,欲快速以 Nginx 做前端反向代理,Apache 配置不動。

1. 編輯 nginx.conf (server 區塊)

server {
    listen 81;
    server_name website.com;
    location / {
        proxy_pass https://website.com;
    }
}

2. 語法檢查 (必做)

sudo /usr/local/nginx/sbin/nginx -t
# 成功輸出:
# nginx: the configuration file ... syntax is ok
# nginx: configuration file ... test is successful

每行必須以分號結尾,否則易報誤導性錯誤 (如缺少 })。配置錯誤可能導致進程失控,甚至 stop 無效,需 sudo killall nginx 強制殺死。

3. 重新載入生效

sudo /etc/init.d/nginx reload

4. 驗證

瀏覽器訪問 https://website.com:81,Chrome 開發者工具 Network 標籤查看第一個請求的 Response Header Server: nginx 確認生效。

Response Header 顯示 Server: nginx

Copyright © Windows教程網 All Rights Reserved