>  기사  >  백엔드 개발  >  Mac에서 nginx + tomcat7 로드 밸런싱

Mac에서 nginx + tomcat7 로드 밸런싱

WBOY
WBOY원래의
2016-08-08 09:24:081037검색

1. Tomcat 설치:

Tomcat 공식 웹사이트(http://tomcat.apache.org/download-70.cgi)로 이동하여 해당 버전을 다운로드합니다.

지정된 디렉터리에 압축을 풉니다. :

localhost:tomcat rolin$ pwd

/Users/rolin/soft/tomcat #내 디렉터리

복사 1개 게재:

localhost:tomcat rolin$ ll

총 0

drwxr-xr-x 13 rolin 직원 442 5 15 23:43 apache-tomcat-7.0.62-1

drwxr-xr- x 13 rolin Staff 442 5 15 23:44 apache-tomcat-7.0.62-2

구성 파일 내용:

conf/server.xml

localhost:tomcat rolin$ cat apache-tomcat-7.0.62-1/conf/server.xml


< GlobalNamingResources>

type="org.apache.catalina. UserDatabase"

Description="업데이트하고 저장할 수 있는 사용자 데이터베이스"

Factory="org.apache.catalina.users.MemoryUserDatabaseFactory "

pathname="conf/tomcat-users.xml" />


<커넥터 포트="8081 " 프로토콜 ="HTTP/1.1"

connectionTimeout="20000"

redirectPort="8444" />

<엔진 이름="Catalina" defaultHost= "localhost">

  < ;Realm className="org.apache.catalina.realm.UserDatabaseRealm"

                 resourceName="UserDatabase"/>

            

& lt; hst name = "localhost" appBase = "webapps"

unpackwars = "true" autodeploy = "true" & gt;

              패턴="%h %l %u %t "%r" %s %b" /> ;

localhost:tomcat rolin$ cat apache-tomcat-7.0.62-2/ conf/server.xml


< !--

하나 이상의

기여자 라이센스 계약에 따라 Apache Software Foundation(ASF)에 라이센스가 부여되었습니다.

저작권 소유에 관한 추가 정보는 이 저작물을 참조하세요.

  ASF는 Apache 라이센스 버전 2.0

("라이센스")에 따라 귀하에게 이 파일에 대한 라이센스를 부여합니다.

라이선스를 준수하지 않는 한 이 파일을 사용할 수 없습니다.  라이센스 사본은


      http://www.apache.org/licenses/LICENSE-에서 얻을 수 있습니다. 2.0


  관련 법률에서 요구하거나 서면으로 동의하지 않는 한, 소프트웨어

  라이선스에 따라 배포되는 것은 명시적이든 묵시적이든 어떤 종류의 보증이나 조건 없이 "있는 그대로"

  배포됩니다.

  라이선스에 따른 권한 및

제한 사항을 관리하는 특정 언어는 라이선스를 참조하세요.

-->

 

 

 

 

 

 

 

 

 

 


  < !-- 전역 JNDI 리소스

       /docs/jndi-resources-howto.html

에 있는 설명서 -->

 

   

   

              type="org.apache.catalina.UserDatabase"

              Description="업데이트하고 저장할 수 있는 사용자 데이터베이스"

> 🎜>

 

 

  <서비스 이름="Catalina">

   



   

   

   

    <엔진 이름="Catalina" defaultHost="localhost">

     

     

     

     

       

       

               resourcesName="UserDatabase"/ >

     

      <호스트 이름 ="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">

       

       

       

       

접두사="localhost_access_log." suffix=".txt"

               패턴="%h %l %u %t "%r" %s %b" />

>

시작:

./apache-tomcat-7.0.62-1/bin/startup.sh

./apache-tomcat-7.0.62-2/bin/startup.sh

주소:

http: //localhost:8081 /


고양이가 맞습니다.

2.nginx 설치:

Mac에서는 Brew를 사용하여 설치됩니다

brew: 설치하려면 sudo 권한이 필요합니다.

curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/ local --strip 1

nginx 설치 명령:

brew nginx 설치


버전 보기

nginx -V


nginx 구성

localhost:tomcat rolin$ cat /usr/local/etc/nginx/nginx.conf


#user none;

worker_processes 2;


#error_log 로그/error.log;

#error_log 로그/error.log 공지;

#error_log 로그/error.log 정보;


#pid 로그/nginx.pid;



이벤트{

작업자 연결 1024;

}



http {

include mime.types;

default_type 애플리케이션/octet-stream ;


#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

> _for" ';

#access_log 로그/access.log main;


파일 보내기;

#tcp_nopush 켜기;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;


upstream localhost{ #여기에서 tomcat 주소를 구성하세요

> > }

서버 {

80; #nginx 수신 포트를 듣고 tomcat -r을 사용하여 반복하지 마세요.

        charset utf-8;


        #access_log logs/host.access.log main;


        위치 / {

            루트   html;

            index  index.html index.htm;

            Proxy_pass http://localhost;

            Proxy_set_header X-Real- IP $remote_addr;

            Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            Proxy_redirect HOST default;

        }


        #error_page  404              /404.html;


        # 서버 오류 페이지를 정적 페이지로 리디렉션 /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            루트   html ;

        }


        # PHP 스크립트를 127.0.0.1에서 수신하는 Apache로 프록시합니다. :80

        #

        #location ~ .php$ {

        #    Proxy_pass   http: //127.0.0.1;

        #}


        # 통과 127.0.0.1:9000

        #

        #location ~ .php$ {

을 수신하는 FastCGI 서버에 대한 PHP 스크립트

        #    루트           html;

        #    fastcgi_pass   127.0.0.1:9000;

       #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}



        # Apache의 경우 .htaccess 파일에 대한 액세스를 거부합니다. 문서 루트

        # nginx의 것과 일치합니다

        #

        #location ~ /.ht {

        #    모두 거부;

        #}

    }



    # IP, 이름 및 이름을 혼합하여 사용하는 또 다른 가상 호스트 포트 기반 구성

    #

    #server {

    #    듣기       8000;

    #    듣기       somename:8080;

    #    server_name  somename  별칭  another.alias;


    #    위치 / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}



    # HTTPS 서버

    #

    #server {

    #    듣기       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;


# 위치 / {

# 루트 html;

# 인덱스 인덱스 index.html index.htm;

# }

#}


}

포함 서버/ * ;



nginx 서비스 시작

sudo nginx


방문

브라우저 주소 표시줄: http://localhost/

nginx 서비스 종료

sudo nginx -s stop


위 내용은 관련 내용을 포함하여 Mac에서의 nginx + tomcat7 로드 밸런싱을 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.