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

首頁 > 網站 > Nginx > 正文

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

2024-08-30 12:25:58
字體:
來源:轉載
供稿:網友

由于公司使用過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配置

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

#Nginx所用用戶和組#user nobody;#工作的子進程數量(通常等于CPU數量或者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 {  #使用網絡IO模型linux建議epoll,FreeBSD建議采用kqueue  #use epoll;  #使用epoll模型提高性能 win下不需要  #use epoll;  #允許最大連接數  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;  # 啟用內核復制模式,應該保持開啟達到最快IO效率  sendfile    on;  #tcp_nopush   on;  #keepalive_timeout 0;  # HTTP1.1支持持久連接alive  # 降低每個連接的alive時間可在一定程度上提高可響應連接數量,所以一般可適當降低此值  keepalive_timeout 65;  # 啟動gzip壓縮功能設置,有效降低網絡流量  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;    # 靜態文件緩存  # 最大緩存數量,文件未使用存活期  open_file_cache max=655350 inactive=20s;  # 驗證緩存有效期時間間隔  open_file_cache_valid 30s;  # 有效期內文件最少使用次數  open_file_cache_min_uses 2;    #xbq add  #upstream作負載均衡,在此配置需要輪詢的服務器地址和端口號,max_fails為允許請求失敗的次數,默認為1.  #weight為輪詢權重,根據不同的權重分配可以用來平衡服務器的訪問率。  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文件夾,用于存放靜態資源        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;      # 真實的用戶訪問協議      proxy_set_header X-Forwarded-Proto $scheme;            # 默認值default,      # 后端response 302時 tomcat header中location的host是http://192.168.1.62:8080      # 因為tomcat收到的請求是nginx發過去的, nginx發起的請求url host是http://192.168.1.62:8080      # 設置為default后,nginx自動把響應頭中location host部分替換成當前用戶請求的host部分      # 網上很多教程將此值設置成 off,禁用了替換,      # 這樣用戶瀏覽器收到302后跳到http://192.168.1.62:8080,直接將后端服務器暴露給瀏覽器      # 所以除非特殊需要,不要設置這種畫蛇添足的配置      proxy_redirect default;      client_max_body_size 10m;  #允許客戶端請求的最大單文件字節數      client_body_buffer_size 128k; #緩沖區代理緩沖用戶端請求的最大字節數      proxy_connect_timeout 90;  #nginx跟后端服務器連接超時時間      proxy_read_timeout 90;   #連接成功后,后端服務器響應時間      proxy_buffer_size 4k;    #設置代理服務器(nginx)保存用戶頭信息的緩沖區大小      proxy_buffers 6 32k;    #proxy_buffers緩沖區,網頁平均在32k以下的話,這樣設置      proxy_busy_buffers_size 64k;#高負荷下緩沖大小(proxy_buffers*2)      proxy_temp_file_write_size 64k; #設定緩存文件夾大小,大于這個值,將從upstream服務器傳          }        #xbq add    #配置Nginx動靜分離,定義的靜態頁面直接從/usr/nginxStaticFile(Nginx發布目錄)讀取。    location ~/.(gif|jpg|jpeg|png|css|js|php)$ {            #expires定義用戶瀏覽器緩存的時間為7天,如果靜態頁面不常更新,可以設置更長,這樣可以節省帶寬和緩解服務器的壓力  E:/staticResource;      expires 7d;    }        #xbq add    #啟用nginx status 監聽頁面    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;  #  }  #}}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 托里县| 阜康市| 南郑县| 金坛市| 罗平县| 登封市| 望奎县| 平度市| 庄河市| 靖边县| 宁陕县| 普宁市| 邹平县| 阿尔山市| 聂拉木县| 建宁县| 三门峡市| 博野县| 肥城市| 林甸县| 崇礼县| 鄂州市| 平武县| 蒙自县| 沿河| 二连浩特市| 蒙自县| 萨迦县| 东丽区| 长海县| 右玉县| 监利县| 永定县| 惠来县| 泽库县| 和平县| 安宁市| 通辽市| 镇安县| 宝兴县| 琼结县|