nginx代理tomcat配置

===============================只有一个应用的时候的直接代理=================================

#usernobody;

worker_processes1;

#error_loglogs/error.log;

#error_loglogs/error.lognotice;

#error_loglogs/error.loginfo;

pidlogs/nginx.pid;

events{

worker_connections1024;

}

http{

includemime.types;

default_typeapplication/octet-stream;

includeproxy.conf;#一定要指向代理文件

#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'

#'$status$body_bytes_sent"$http_referer"'

#'"$http_user_agent""$http_x_forwarded_for"';

#access_loglogs/access.logmain;

sendfileon;

tcp_nopushon;

#keepalive_timeout0;

keepalive_timeout65;

#gzipon;

server{

listen80;

server_namelocalhost;

indexindex.d;

#rootD:/tools/java/tomcat/apache-tomcat-7.0.16/webapps/dabichong/;

#charsetkoi8-r;

charsetgb2312;

#access_loglogs/host.access.logmain;

location~^/(images|pages|javascript|js|css|flash|media|static)/{

rootD:/tools/java/tomcat/apache-tomcat-7.0.16/webapps/dabichong/;

#expires30d;

}

#location/{

#rootD:/tools/java/tomcat/apache-tomcat-7.0.16/webapps/dabichong/;

#indexindex.dindex.htm;

#proxy_passhttp://127.0.0.1:8080;#主要在这里,设置一个代理

#}

#location~.*.d${#matchingtomcat

location/{

indexindex.d;

rootD:/tools/java/tomcat/apache-tomcat-7.0.16/webapps/dabichong/;

proxy_passhttp://127.0.0.1:8080;#主要在这里,设置一个代理

}

#location~.*.dpkg${#matchingtomcat

#indexindex.d;

#proxy_passhttp://127.0.0.1:8080;#主要在这里,设置一个代理

#}

location/NginxStatus{

stub_statuson;

access_logon;

auth_basic"NginxStatus";

}

#error_page404/404.html;

#redirectservererrorpagestothestaticpage/50x.html

#

error_page500502503504/50x.html;

location=/50x.html{

roothtml;

}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80

#

#location~\.php${

#proxy_passhttp://127.0.0.1;

#}

#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000

#

#location~\.php${

#roothtml;

#fastcgi_pass127.0.0.1:9000;

#fastcgi_indexindex.php;

#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;

#includefastcgi_params;

#}

#denyaccessto.htaccessfiles,ifApache'sdocumentroot

#concurswithnginx'sone

#

#location~/\.ht{

#denyall;

#}

}

#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration

#

#server{

#listen8000;

#listensomename:8080;

#server_namesomenamealiasanother.alias;

#location/{

#roothtml;

#indexindex.htmlindex.htm;

#}

#}

#HTTPSserver

#

#server{

#listen443;

#server_namelocalhost;

#sslon;

#ssl_certificatecert.pem;

#ssl_certificate_keycert.key;

#ssl_session_timeout5m;

#ssl_protocolsSSLv2SSLv3TLSv1;

#ssl_ciphersHIGH:!aNULL:!MD5;

#ssl_prefer_server_cipherson;

#location/{

#roothtml;

#indexindex.htmlindex.htm;

#}

#}

}

===========================代理到指定应用=====================================

#Thedefaultserver

#

server{

listen80;

server_namewwww.xxxxx.com;

#charsetkoi8-r;

#access_loglogs/host.access.logmain;

location~^/app1/(images|pages|javascript|js|css|flash|media|static)/{

root/home/apache-tomcat-7.0.22/webapps;

#expires30d;

}

location~^/app1/(.*.jpg|.*.gif|.*.png|.*.bmp)/{

root/home/apache-tomcat-7.0.22/webapps;

}

location/app1{

indexsys.index.d;

proxy_passhttp://127.0.0.1:8080$request_uri;

}

location/app2_sample{

set$fixed_destination$http_destination;

if($http_destination~*^https(.*)$){

set$fixed_destinationhttp$1;

}

proxy_set_headerHost$host;

proxy_set_headerX-Real-IP$remote_addr;

proxy_set_headerDestination$fixed_destination;

proxy_passhttp://223.4.89.162$request_uri;

}

location/{

root/usr/local/nginx/html;

indexindex.htmlindex.htm;

}

error_page404/404.html;

location=/404.html{

root/usr/local/nginx/html;

}

#redirectservererrorpagestothestaticpage/50x.html

#

error_page500502503504/50x.html;

location=/50x.html{

root/usr/local/nginx/html;

}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80

#

#location~\.php${

#proxy_passhttp://127.0.0.1;

#}

#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000

#

#location~\.php${

#roothtml;

#fastcgi_pass127.0.0.1:9000;

#fastcgi_indexindex.php;

#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;

#includefastcgi_params;

#}

#denyaccessto.htaccessfiles,ifApache'sdocumentroot

#concurswithnginx'sone

#

#location~/\.ht{

#denyall;

#}

}

=====================tomcat配置========================

<Hostname="localhost"appBase="D:\tools\java\tomcat\apache-tomcat-7.0.16\webapps\"

unpackWARs="true"autoDeploy="true">

<!--SingleSignOnvalve,shareauthenticationbetweenwebapplications

Documentationat:/docs/config/valve.html-->

<!--

<Valveclassname="org.apache.catalina.authenticator.SingleSignOn"/>

-->

<Contextpath=""docBase="dabichong"debug="0"reloadable="true"/>

相关推荐