時間:2024-01-05 15:24:01 | 來源:網(wǎng)站運營
時間:2024-01-05 15:24:01 來源:網(wǎng)站運營
Nginx 常用配置清單有哪些?:nginx在兩處會發(fā)揮作用:cp /etc/nginx/sites-available/default default.bakvim /etc/nginx/sites-available/default
server #網(wǎng)站配置區(qū)域{ listen 80; #默認監(jiān)聽80端口 server_name www.lulu.com; #提供服務的域名主機名 location / { root html; #站點根目錄(這里html是相對路徑,默認網(wǎng)站根目錄為:/usr/local/nginx/html) index index.thml index.htm; #默認首頁文件,多個用空格分開 } error_page 500 502 503 504 /50x.html; #出現(xiàn)對應http狀態(tài)碼時,使用50x.html回應客戶 location = /50x.thml { root html; #指定對應目錄 }}
server { listen 80; server_name 192.168.4.32; #監(jiān)聽地址 location / { root html; #/html目錄 proxy_pass http://127.0.0.1:8080; #請求轉向 index index.html index.htm; #設置默認頁 } }
upstream myserver { server 192.167.4.32:5000; server 192.168.4.32:8080; } server { listen 80; #監(jiān)聽端口 server_name 192.168.4.32; #監(jiān)聽地址 location / { root html; #html目錄 index index.html index.htm; #設置默認頁 proxy_pass http://myserver; #請求轉向 myserver 定義的服務器列表 } }
user nginx_wb; #Linux下使用 top查尋后顯示的用戶名稱# worker_processes 值越大,可以支持的并發(fā)處理量就越多 worker_processes auto; pid /run/nginx.pid;include /etc/nginx/modules-enabled/*.conf;daemon off;events { #支持的最杭州接數(shù)1024 默認為512 worker_connections 768; accept_mutex on; #設置網(wǎng)路連接序列化,防止驚群現(xiàn)象發(fā)生,默認為on multi_accept off; #設置一個進程是否同時接受多個網(wǎng)絡連接,默認為off}http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; #Nginx 的默認值是 65 秒,有些瀏覽器最多只保持60秒,所以可設定為 60 秒。若將它設置為 0,就禁止了keepalive連接。 keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; #sendfile_max_chunk 100k; #每個進程每次調用傳輸數(shù)量不能大于設定的值,默認為0,即不設上限。 # server_names_hash_bucket_size 64; # server_name_in_redirect off; ###定義上游服務器(需要被nginx真實代理訪問的服務器),和下面的server配套使用 upstream backServer{ #輪詢服務器,weight為服務器權重,與訪問頻率成正比,max_fails最大超時次數(shù),fail_timeout為中斷時間 server 172.16.2.57:8080 weight=3 max_fails=1 fail_timeout=60s; server 172.16.2.57:8081 weight=3 max_fails=1 fail_timeout=60s; #server 192.168.10.121:3333 backup; #熱備 } server { #keepalive_requests 120; #單連接請求上限次數(shù) ##監(jiān)聽的端口號 listen 80; ### 監(jiān)聽地址 服務名稱 server_name www.lzh.com; #### 匹配URL路徑地址 /表示匹配所有路徑地址 默認不區(qū)分大小寫 location / { #故障轉移的條件:如果后端的服務器返回502、504、執(zhí)行超時等錯誤,自動將請求轉發(fā)到upstream負載均衡池中的另一臺服務器,實現(xiàn)故障轉移。 proxy_next_upstream http_502 http_504 error timeout invalid_header; ### 指定上游服務器負載均衡服務器,這個名稱和upstrean后的名稱一致 proxy_pass http://backServer; ###nginx與上游服務器(真實訪問的服務器)超時時間 后端服務器連接的超時時間_發(fā)起握手等候響應超時時間 proxy_connect_timeout 1s; ###nginx發(fā)送給上游服務器(真實訪問的服務器)超時時間 proxy_send_timeout 1s; ### nginx接受上游服務器(真實訪問的服務器)超時時間 proxy_read_timeout 1s; # 重試次數(shù) proxy_next_upstream_tries 3; index index.html index.htm; #deny 127.0.0.1; #拒絕的ip #allow 172.18.5.54; #允許的ip } } include /etc/nginx/mime.types; #文件擴展名與文件類型映射表 default_type application/octet-stream; #默認文件類型,默認為text/plain # SSL Settings ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; # Logging Settings #access_log off; #取消服務日志 access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; # Gzip Settings gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*;}#mail {# # See sample authentication script at:# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript# # # auth_http localhost/auth.php;# # pop3_capabilities "TOP" "USER";# # imap_capabilities "IMAP4rev1" "UIDPLUS";# # server {# listen localhost:110;# protocol pop3;# proxy on;# }# # server {# listen localhost:143;# protocol imap;# proxy on;# }#}
worker_processes 8;# error_log logs/error.log;error_log /dev/null;events { worker_connections 65535;}http { upstream api{ server 10.132.237.12:10523; server 10.132.237.12:10520; } log_format main '$time_iso8601|$remote_addr|' '$http_x_forwarded_for|$status|$request_time|$upstream_response_time|' '$request_length|$body_bytes_sent|$host|$request|$http_referer|$http_user_agent'; server { listen 10521; client_max_body_size 10M; # access_log logs/access.log main; proxy_read_timeout 5; proxy_send_timeout 5; access_log off; location / { proxy_pass http://api/; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }}
關鍵詞:清單,配置
微信公眾號
版權所有? 億企邦 1997-2025 保留一切法律許可權利。