這裏使用 nginx負載兩個tomcat服務javascript
#user nobody;#windows 不配置 #工做的子進程數量(一般等於CPU數量或者2倍於CPU) worker_processes 8; #錯誤日誌存放路徑,默認地址在nginx路徑下的logs下 #error_log logs/error.log; #error_log logs/error.log notice; error_log logs/error.log info; #指定pid存放文件 #pid logs/nginx.pid; events { #容許最大鏈接數 worker_connections 2048; } http { include mime.types; default_type application/octet-stream; #定義日誌格式 #log_format main '$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_timeout 0; keepalive_timeout 65; gzip on; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; upstream mytomcat{#mytomcat與 location的 proxy_pass的值對應 ip_hash;#確保每一個訪問的ip每次sessoion只訪問到一個服務 #weigth參數表示權值,權值越高被分配到的概率越大 #server 127.0.0.1:8080 weight=1 ; server 127.0.0.1:8080;#tomcat6 server 127.0.0.1:8888;#tomcat6 } server { listen 80; server_name mpc; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.jsp index.html index.htm; proxy_pass http://mytomcat;#upstream 對應 proxy_set_header Host $host; #後端的Web服務器能夠經過X-Forwarded-For獲取用戶真實IP。 client_max_body_size 10m; #容許客戶端請求的最大單文件字節數。 client_body_buffer_size 128k; #緩衝區代理緩衝用戶端請求的最大字節數。 proxy_connect_timeout 3; #Nginx跟後端服務器鏈接超時時間。超時會鏈接到另一臺服務器 proxy_read_timeout 90; #鏈接成功後,後端服務器響應時間。 proxy_buffer_size 4k; #設置代理服務器保存用戶頭信息的緩衝區大小。 proxy_buffers 6 32k; #proxy_buffers緩衝區。 proxy_busy_buffers_size 64k; #高負荷下緩衝大小。 proxy_temp_file_write_size 64k; #設定緩存文件夾大小。 } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
location ~ .*\.(txt|pdf|doc|xls|docx|xlsx|zip|rar)$ {
if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls|docx|xlsx|zip|rar)$){
add_header Content-Disposition: 'attachment;';
}
root /app/html;
index index.html index.htm;
}php
start nginx #啓動nginx nginx -s quit #關閉nginx 慢慢關閉? nginx -s stop #中止nginx 跟關閉相似,直接關閉? nginx -s reload #修改了配置文件從新加載
隨着訪問量愈來愈大,nginx的日誌文件會不斷增大,會致使日誌寫入時間增長,因此定時備份切割日誌文件是必須的,這裏寫一個windows下定時將日誌文件備份狀況的命令行:css
@echo off echo 備份日誌文件 #取到當前全部日誌文件數量 for /f %%i in ('dir *.log /b/a-d') do set /a num+=1 #備份日誌文件 copy access.log access%num%.log #將一個空日誌文件覆蓋原來的日誌文件 copy /y accessnull.log access.log echo ... echo ... echo 備份完成! #pause