主要設置一些影響nginx 服務器總體運行的配置指令。如:用戶(組),生成worker process 數,日誌存放路徑,配置文件引入,pid文件路徑javascript
影響nginx 服務器與用戶的網絡鏈接。如:每一個worker processs 的最大鏈接數,事件驅動模型css
nginx 配置中的重要部分,代理,緩存等功能均可以在此配置。如:文件引入,mime-type 定義,鏈接超時,單鏈接請求數上限html
與「虛擬主機」的概念有密切關係。每一個server 塊至關於一臺虛擬主機,最多見的兩個配置項是監聽配置和虛擬主機的名稱或IP配置前端
在server 塊中,能夠有多個。地址定向,數據緩存,和應答控制等功能都是在這部分實現。java
#=========================全局塊============================ #user user [grop]; # 指定能夠運行nginx 服務器的用戶及組。只被設置的用戶及組纔有權限管理 #user nobody nobody; # 所用用戶可用,默認配置 user nginx nginx; #worker_processes number | auto; #控制併發處理,值越大,支持的併發數越多 #worker_processes 1; #默認值 ,最多產生1個worker_processes worker_processes auto; #pid file; #pid 存放路徑.相對或絕對路徑 #pid logs/nginx.pid; #默認在安裝目錄logs/nginx.pid pid /var/run/nginx.pid; #error_log file | stder [debug | info | notice | warn | error | crit | alert | emerg]; #錯誤日誌存放路徑 #error_log logs/error.log error; # 可在 全局塊,http 塊 ,serveer 塊,location 塊中配置 error_log /data/wwwlogs/error_nginx.log crit; #include file; #配置文件引入,能夠是相對/絕對路徑。 指令能夠放在配置文件的任意地方(任意塊中) worker_rlimit_nofile 51200; #===========================events 塊=============================== events { #accept_mutex on|off; #網絡鏈接序列化。解決「驚羣」問題 accept_mutex on; #默認爲開啓狀態 #multi_accept on|off; #是否容許worker process同時接收多個網絡鏈接, multi_accept off; #默認爲關閉 #use method; #事件驅動模型選擇,select 、 poll 、 kqueue 、 epoll 、 rtsig 、 /dev/poll 、 eventport use epoll; #worker_connections number; #worker process 的最大鏈接數。 worker_connections 512; #默認值爲512。注意設置不能大於操做系統支持打開的最大文件句柄數量。 } #==========================http塊============================ http { #定義 mime-type (網絡資源的媒體類型)。 指定能識別前端請求的資源類型 include mime.types; #引入外部文件 ,在外部文件中有定義types 塊 default_type application/octet-stream; #默認爲 text/plain 。 http塊、server塊、location塊中可配置 #access_log path [format[buffer=size]]; #定義服務日誌,記錄前端的請求日誌 #access_log logs/access.log combined; #combined 是默認定義的日誌格式字符串名稱 access_log off; #關閉日誌 #log_format name stirng #定義了日誌格式,以便access_log 使用 #log_format combined '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #sendfile on|off; #配置容許 sendfile 方式傳輸文件 sendfile off; #默認關閉,可在http塊、server塊、location塊 中定義 #sendfile_max_chunk size; #配置worker process 每次調用sendfile()傳輸的數據最最大值 #sendfile_max_chunk 0; #默認爲0 不限制。 可在http塊、server塊、location塊 中定義 sendfile_max_chunk 128k; #keepalive_timeout timeout [header_timeout]; #配置鏈接超時時間, 可在http塊、server塊、location塊 中定義 #keepalive_timeout 75s; #默認爲75秒,與用戶創建會話鏈接後,nginx 服務器能夠保持這些鏈接打開的時間。 keepalive_timeout 120 100s; #在服務器端保持鏈接的時間設置爲120s,發給用戶端的應答報文頭部中keep-alive 域的設置爲100s #keepalive_requests number; #單鏈接請求數上限 keepalive_requests 100; #默認爲 100 server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 1024m; tcp_nopush on; server_tokens off; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; #Gzip Compression gzip on; gzip_buffers 16 8k; gzip_comp_level 6; gzip_http_version 1.1; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text/javascript application/javascript application/x-javascript text/x-json application/json application/x-web-app-manifest+json text/css text/plain text/x-component font/opentype application/x-font-ttf application/vnd.ms-fontobject image/x-icon; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency. open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; ######################## default ############################ # server { # listen 8067; # server_name _; # access_log /data/wwwlogs/access_nginx.log combined; # root /data/wwwroot/default; # index index.html index.htm index.jsp; # location /nginx_status { # stub_status on; # access_log off; # allow 127.0.0.1; # deny all; # } # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { # expires 30d; # access_log off; # } # location ~ .*\.(js|css)?$ { # expires 7d; # access_log off; # } # location ~ { # proxy_pass http://127.0.0.1:8080; # include proxy.conf; # } # } # server{ # listen 8087; # server_name _; # root /home/wwwroot/default; # location / { # } # } upstream backend{ server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=2; server 139.224.209.104:8080 backup; } server{ listen 80; listen 443 ssl; server_name wmcenter.xy-asia.com; #ssl on; default_type 'text/html'; charset utf-8; ssl_certificate /usr/local/cert/1634560_wmcenter.xy-asia.com.pem; ssl_certificate_key /usr/local/cert/1634560_wmcenter.xy-asia.com.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; root html; index index.html index.htm; location ~ .*\.(js|css)?$ { expires 1h; proxy_pass http://backend; } location / { proxy_pass http://backend; add_header backendIP $upstream_addr; #proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; #proxy_set_header Host $host; #proxy_set_header X-Real-IP $remote_addr; #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header X-Forwarded-Proto https; #proxy_redirect http://http://127.0.0.1:8080 $scheme://127.0.0.1:8080; #port_in_redirect on; #proxy_redirect off; include proxy.conf; } #error_log /home/wwwlogs/xywm.log; } #緩存配置 proxy_temp_file_write_size 264k; proxy_temp_path /data/wwwlogs/nginx_temp; proxy_cache_path /data/wwwlogs/nginx_cache levels=1:2 keys_zone=prc:200m inactive=5d max_size=400m; proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; ########################## vhost ############################# include vhost/*.conf; }