🖥️ Nginx Config Generator

Nginx Config Generator - Pick static site or reverse proxy and fill params to emit a server block config. Free, browser-only.

📐 工作原理與說明
按模式取值:域名為空時用下劃線佔位;域名逐項校驗只允許字母/數字/點/連字元/下劃線/萬用字元;靜態目錄與證書路徑校驗為以 / 開頭的可列印 ASCII 且不得含分號、大括號、$ 或控制字元,含空格的路徑輸出時加雙引號並按 Nginx 語法轉義引號與反斜槓;反向代理地址用 URL 解析校驗 http/https;埠必須是 1–65535 的整數。靜態模式生成 server 塊,依次寫入監聽埠、服務名、根目錄、預設首頁,以及「依次嘗試請求路徑、路徑作為目錄、否則返回 404」的 location;反向代理模式生成 server 塊,依次寫入監聽埠、服務名,以及把請求轉發到所填上游地址的 location,並設定轉發請求頭中的主機名與客戶端真實地址。輸出時對整段配置做 HTML 轉義後在程式碼塊中展示
按場景生成 Nginx server 配置。
  • 場景:靜態站點、反向代理、HTTPS、負載均衡、單頁應用(SPA)回退。
  • 核心項:listen 埠、server_name、root/index、location 匹配規則與優先順序。
  • HTTPS:ssl_certificate、ssl_certificate_key,並限制協議版本與加密套件。
  • 反代:需設定 proxy_set_header 傳遞真實客戶端 IP,否則後端日誌全是代理 IP。

Formula & Standard References

Item Formula / Note Source / Standard
Config hierarchy main, events, http, server and location contexts nginx documentation
Reverse proxy proxy_pass forwards upstream; proxy_set_header passes headers nginx documentation
Location matching exact = first, then ^~ prefix, then regex, then prefix nginx documentation
⚠️ 使用說明與注意事項

📋 常用指令

指令作用
try_files靜態回退
proxy_pass轉發上游
nginx -t校驗語法