第一步: 下載下傳: nginx nginx 下載下傳位址: http://nginx.org/en/download.html tomcat 下載下傳位址: http://tomcat.apache.org/download-70.cgi 第二步:配置 第三步,開啟 建立檔案夾: nginx+tomcat 将兩個檔案放在目前檔案夾 3.1 解壓 nginx ,解壓導目前檔案夾 3.2 進入目錄 在 nginx 目錄下,找到 nginx.exe 輕按兩下 3.3 檢視程序
結束 nginx 程序: 3.3 . 1 直接點選結束 通過指令: 快速停止或關閉 nginx 指令: nginx -s stop 正常停止或關閉 nginx 指令: nginx -s quit 配置檔案修改重裝載指令: nginx -s reload 3.4 測試通路 顯示 welcome to nginx 說明成功
4. 打包項目為 war 包 4.1.1 普通項目打包: 《 1 》選中項目 ---à 點選右鍵 ---àexport--à 選中 war file-à 《 2 》 Mave 項目導出 war 檔案: 選中項目 ---à 點選右鍵 ---à run as (debug as )-à maven install 4.2.1 解壓 tomcat 解壓到目前檔案夾。後重命名為 tomcat1 和 tomcat2 然後打開 Tomcat 的 conf 目錄下的 server.xml ,修改這兩個 Tomcat 的啟動端口,分别為 8090 和 8100 。 這是 tomcat1 ,我是在預設端口上都加的 10 , tomcat2 在預設端口都加 20
這樣兩個 tomcat 就能同時啟動
把解壓好的項目通常放在和 tomcat 同一級,而不是放在 tomcat webapp 裡
在兩個 tomcat conf 檔案夾下 server.xml 檔案裡 找到 139 行
在下面添加如下語句 路徑是你解壓好項目的路徑
<Context path="" docBase="D:\ruan-jian\tomcat+ning-jiqun\bbs"/> 5.1 整合 nginx+tomcat 5.1.1 配置 nginx 打開 nginx -1.1.14 檔案夾 --->conf 檔案夾 ---> 打開 nginx.conf 檔案 注意下面的配置檔案是按照我 目前 tomcat 的端口來進行配置的 也就是 8090 和 8100 ; 如果 改動端口 則需要更改此配置檔案; #user nobody;# 配置使用者或者組,預設為 nobody nobody 。 worker_processes 1;# 允許生成的程序數,預設為 1 #error_log logs/error.log;# 制定日志路徑,級别。這個設定可以放入全局塊, http 塊, server 塊,級别以此為: debug|info|notice|warn|error|crit|alert|emerg #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; # 指定 nginx 程序運作檔案存放位址 events { accept_mutex on; # 設定網路連接配接序列化,防止驚群現象發生,預設為 on multi_accept on; # 設定一個程序是否同時接受多個網絡連接配接,預設為 off #use epoll; # 事件驅動模型, select|poll|kqueue|epoll|resig|/dev/poll|eventport worker_connections 1024;# 最大連接配接數,預設為 512 } http { include mime.types;# 檔案擴充名與檔案類型映射表 default_type application/octet-stream;# 預設檔案類型,預設為 text/plain #access_log off; # 取消服務日志 #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;# 允許 sendfile 方式傳輸檔案,預設為 off ,可以在 http 塊, server 塊, location 塊。 #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 60; # 連接配接逾時時間,預設為 75s ,可以在 http , server , location 塊。 gzip on; upstream mysvr { ip_hash; server 127.0.0.1:8090 weight=1; server 127.0.0.1:8100 weight=1; } server { listen 89;# 監聽端口 server_name localhost;# 監聽位址 #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://mysvr; # 請求轉向 mysvr 定義的伺服器清單 } #error_page 404 /404.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 8009; # listen somename:8089; # 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; # } #} } 測試是否成功:啟動順序 先啟動 nginx ,之後再啟動 tomcat 兩者之間的以來關系,是以要按照順序來開啟 Nginx 通路項目路徑: http://localhost:89/ 5.2.1 如何判斷浏覽器使用的是哪個伺服器? 修改 tomcat 檔案夾下 conf 目錄下的 server 檔案第 105 行
5.3 session 共享問題 在項目的 web.xml 檔案最後加上 <distributable/> ,如下圖