国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Tomcat > 正文

詳解Ngigx+Tomcat配置動靜分離,負載均衡

2024-09-06 19:00:49
字體:
來源:轉載
供稿:網(wǎng)友
本篇文章主要介紹了Ngigx+Tomcat配置動靜分離,負載均衡,具有一定的參考價值,有需要的可以了解一下。

由于公司使用過Ngnix,對于剛接觸Nginx來說,感覺有些好奇,于是研究了下。

本人在windows下使用的版本是nginx-1.8.1:

1. 啟動Ngnix

雙擊nginx-1.8.1文件夾中nginx.exe,當任務管理器中存在兩個nginx進程時,則說明啟動成功!

2. Ngnix常用命令

nginx -s stop 強制關閉 nginx -s quit 安全關閉 nginx -s reload 改變配置文件的時候,重啟nginx工作進程,來時配置文件生效   nginx -s reopen 打開日志文件

3. Nginx配置

下面配置綜合了網(wǎng)上的資料,記下,防止自己忘記。

#Nginx所用用戶和組#user nobody;#工作的子進程數(shù)量(通常等于CPU數(shù)量或者2倍于CPU)worker_processes 1;#錯誤日志存放路徑#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#指定pid存放文件#pid    logs/nginx.pid;events {  #使用網(wǎng)絡IO模型linux建議epoll,F(xiàn)reeBSD建議采用kqueue  #use epoll;  #使用epoll模型提高性能 win下不需要  #use epoll;  #允許最大連接數(shù)  worker_connections 1024;}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;  # 啟用內(nèi)核復制模式,應該保持開啟達到最快IO效率  sendfile    on;  #tcp_nopush   on;  #keepalive_timeout 0;  # HTTP1.1支持持久連接alive  # 降低每個連接的alive時間可在一定程度上提高可響應連接數(shù)量,所以一般可適當降低此值  keepalive_timeout 65;  # 啟動gzip壓縮功能設置,有效降低網(wǎng)絡流量  gzip on;  gzip_min_length 1k;  #最小1K  gzip_buffers  4 16k;  gzip_http_version 1.0;  gzip_comp_level 2;  gzip_types text/plain application/x-javascripttext/css application/xml;  gzip_vary on;    # 靜態(tài)文件緩存  # 最大緩存數(shù)量,文件未使用存活期  open_file_cache max=655350 inactive=20s;  # 驗證緩存有效期時間間隔  open_file_cache_valid 30s;  # 有效期內(nèi)文件最少使用次數(shù)  open_file_cache_min_uses 2;    #xbq add  #upstream作負載均衡,在此配置需要輪詢的服務器地址和端口號,max_fails為允許請求失敗的次數(shù),默認為1.  #weight為輪詢權重,根據(jù)不同的權重分配可以用來平衡服務器的訪問率。  upstream hostname {    server 127.0.0.1:9000 max_fails=0 weight=2;    server 127.0.0.1:9001 max_fails=0 weight=2;  }  server {    listen    8181;    server_name localhost;    #charset koi8-r;    #access_log logs/host.access.log main;    root /img; #在nginx-1.8.1文件夾中新建img文件夾,用于存放靜態(tài)資源        location / {      #root  html;      #index index.html index.htm;      #xbq add      proxy_pass http://hostname;      #下面三條指令允許重新定義和添加一些將被轉移到被代理服務器的請求頭部信息      # 請求頭中Host信息      proxy_set_header Host $host;      # 真實的客戶端IP      proxy_set_header X-Real-IP $remote_addr;      # 代理路由信息,此處取IP有安全隱患      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;      # 真實的用戶訪問協(xié)議      proxy_set_header X-Forwarded-Proto $scheme;            # 默認值default,      # 后端response 302時 tomcat header中l(wèi)ocation的host是http://192.168.1.62:8080      # 因為tomcat收到的請求是nginx發(fā)過去的, nginx發(fā)起的請求url host是http://192.168.1.62:8080      # 設置為default后,nginx自動把響應頭中l(wèi)ocation host部分替換成當前用戶請求的host部分      # 網(wǎng)上很多教程將此值設置成 off,禁用了替換,      # 這樣用戶瀏覽器收到302后跳到http://192.168.1.62:8080,直接將后端服務器暴露給瀏覽器      # 所以除非特殊需要,不要設置這種畫蛇添足的配置      proxy_redirect default;      client_max_body_size 10m;  #允許客戶端請求的最大單文件字節(jié)數(shù)      client_body_buffer_size 128k; #緩沖區(qū)代理緩沖用戶端請求的最大字節(jié)數(shù)      proxy_connect_timeout 90;  #nginx跟后端服務器連接超時時間      proxy_read_timeout 90;   #連接成功后,后端服務器響應時間      proxy_buffer_size 4k;    #設置代理服務器(nginx)保存用戶頭信息的緩沖區(qū)大小      proxy_buffers 6 32k;    #proxy_buffers緩沖區(qū),網(wǎng)頁平均在32k以下的話,這樣設置      proxy_busy_buffers_size 64k;#高負荷下緩沖大小(proxy_buffers*2)      proxy_temp_file_write_size 64k; #設定緩存文件夾大小,大于這個值,將從upstream服務器傳          }        #xbq add    #配置Nginx動靜分離,定義的靜態(tài)頁面直接從/usr/nginxStaticFile(Nginx發(fā)布目錄)讀取。    location ~/.(gif|jpg|jpeg|png|css|js|php)$ {            #expires定義用戶瀏覽器緩存的時間為7天,如果靜態(tài)頁面不常更新,可以設置更長,這樣可以節(jié)省帶寬和緩解服務器的壓力  E:/staticResource;      expires 7d;    }        #xbq add    #啟用nginx status 監(jiān)聽頁面    location /nginxstatus {      stub_status on;      access_log on;    }    #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;  #  }  #}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿荣旗| 蓬莱市| 松原市| 康马县| 锦州市| 三明市| 织金县| 崇州市| 平凉市| 阳山县| 德江县| 茌平县| 汝南县| 光山县| 奉新县| 麻江县| 上虞市| 互助| 钦州市| 长汀县| 聂荣县| 塔河县| 文昌市| 福贡县| 敦化市| 大兴区| 云和县| 扶沟县| 蒙城县| 阿图什市| 长治县| 平武县| 延川县| 沅江市| 巴彦县| 武强县| 浠水县| 罗定市| 利津县| 竹山县| 泗洪县|