「三」配置語法、配置檔案高亮
阿新 • • 發佈:2022-05-08
原始碼安裝conf檔案高亮
v1.18.0 參考:https://www.cnblogs.com/roinbi/p/13881102.html v1.14.2 下載:wget https://nginx.org/download/nginx-1.14.2.tar.gz vim高亮指令碼:sudo cp -r contrib/vim/* /usr/share/vim/vimfiles/http配置的指令塊
- http
- upstream
- server
- location
配置語法
- 配置檔案由指令與指令快構成
- 每條指定以;結尾,指令與引數之間以空格符號分割
- 指令快以{}大括號將多條指令組織在一期
- include語句允許組合多個配置檔案以提升可維護性
- 使用#符號添加註釋,提高可讀性
- 使用$符號使用變數
- 部分指定的擦數支援正則表達
worker_processes 1; #error_log logs/error.log; #pid logs/nginx.pid; events { worker_connections 1024; } #http:指令塊 #include mime.types;:指令 http { #指令名 引數 include mime.types; default_type application/octet-stream; #log_format mainupstream模組:可以實現負載均衡'$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout0; keepalive_timeout 65; server { listen 80; server_name localhost; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 2,1 Top
upstream backend { server backend1.example.com weight=5; #執行realserver,可以賦權重 server backend2.example.com:8080; server unix:/tmp/backend3; server backup1.example.com:8080 backup; #backup表示該節點為熱備節點,啟用節點失效時啟用 server backup2.example.com:8080 down; #下線伺服器,可以在real伺服器需要維護時配置 } server { listen 80; #listen、server_name這些正常配置 server_name www.test.com; location / { proxy_pass http://backend; ##反向代理執行定義的upstream名字 } }