1. 程式人生 > >linux下安裝並配置nginx 多個域名 tomcat叢集

linux下安裝並配置nginx 多個域名 tomcat叢集



一.安裝nignx

解壓 

tar -zxvf nginx-1.8.0.tar.gz

新加資料夾

mkdir /root/nginx

進入目錄
     cd nginx-1.8.0

設定一下配置資訊,或者不執行此步,直接預設配置

 ./configure --prefix=/root/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_realip_module

編譯

make

安裝

make install 

配置兩個專案的tomcat叢集:

cd nginx/conf/

vim nginx.conf

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;

   upstream q1 {

       server127.0.0.1:8080 weight=5;

       server127.0.0.1:8081 weight=5;

       server127.0.0.1:8082 weight=5;

       server127.0.0.1:8083 weight=5;

   }

   upstream  q2 {

       server123.45.22.222:8080 weight=5;

       server123.45.22.222:8090 weight=5;

   }

   server {

       listen      80;

       server_name  localhost;

       #charsetkoi8-r;

       #access_log  logs/host.access.log  main;

       location/專案名1 {

           root   html;

           index  index.html index.htm;

           proxy_pass http://q1;

       }

      location /專案名2 {

           root   html;

           index  index.html index.htm;

           proxy_pass http://q2;

       }

       #error_page  404              /404.html;

80為監聽的預設埠號,可以修改


二.啟動nginx

三.修改server.xml埠號(4個)

cd /usr/local/tomcat04/conf

vim server.xml

注:每個配置檔案修改3個埠號:8005 8009 8080

四.啟4tomcat


-------------------------------------------------------------------------------------

啟動停止重啟與測試
    1) 啟動
        #方法1  指定配置檔案啟動
        # /usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf


        #方法2  預設的配置檔案
        # cd /usr/local/nginx/sbin
        # ./nginx

    2) 停止
        #查詢nginx主程序號
        ps -ef | grep nginx
        #強制停止
        pkill -9 nginx
    3) 重啟
        /usr/local/nginx/sbin/nginx -s reload
    4) 測試
       #測試埠
        netstat -na | grep 80
        #瀏覽器中測試
        http://ip:80