Nginx与Tomcat多端口服务配置实例分享.docx
- 文档编号:10540161
- 上传时间:2023-02-21
- 格式:DOCX
- 页数:32
- 大小:18.23KB
Nginx与Tomcat多端口服务配置实例分享.docx
《Nginx与Tomcat多端口服务配置实例分享.docx》由会员分享,可在线阅读,更多相关《Nginx与Tomcat多端口服务配置实例分享.docx(32页珍藏版)》请在冰豆网上搜索。
Nginx与Tomcat多端口服务配置实例分享
Nginx与Tomcat多端口服务配置实例分享
由于技术研发部在开发三期业务时没有考虑到与二期业务的兼容性,为了保证三期业务上线时不影响二期用户客户端的使用,需要在同一tomcat下部署两个工程。
但由于这两个工程之间需要相互调用,据博主测试这两个工程如果再同一端口下运行时总会有一个工程无法正常请求另一个工程的业务(研发部门未经测试直接交付实施上线【太可怕了】),所以在部署业务时,笔者为了保证业务按时上线采用了在一个Tomcat配置多个端口号以对应不同服务完成业务的正常交付。
一、在Tomcat下配置多个服务,用不同的端口号。
下面以增加1个端口号为例。
具体实施步骤如下所示:
第一步、修改vi/webapp/tomcat6/conf/server.xml文件
具体修改内容如下:
<?
xmlversion='1.0'encoding='utf-8'?
>
<Serverport="8005"
shutdown="SHUTDOWN">
<Resource
name="UserDatabase"auth="Container"
type="org.apache.catalina.UserDatabase"
description="Userdatabasethatcanbeupdatedandsaved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="8080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
<Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host
name="localhost"
appBase="webapps"
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<Contextpath=""docBase="/webapp/tomcat6/webapps/sdmp/"
reloadable="true"></Context>
</Host>
</Engine>
</Service>
<!
—此次向下开始添加新的端口服务-->
<!
--addby
fengzhanhaion2013-->
<Service
name="Catalinai">
<!
—servicename必须要修改成与原servicename不一致-->
<Connector
port="8090"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
<!
—端口号必须修改-->
<Connector
port="8010"protocol="AJP/1.3"
redirectPort="8443"/>
<Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host
name="localhost"
appBase="webapp"
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<!
—appBasename必须要修改-->
<Contextpath=""docBase="/webapp/tomcat6/webapp/mbp/"
reloadable="true"></Context>
<!
—docBase调整至相应appBase属性保证前方代理访问端口号自动调整到该服务--></Host>
</Engine>
</Service>
</Server>
<!
--注意Servicename、Enginename、appBase,端口号别忘了修改,以免重复无法启动-->
第二步、在/webapp/tomcat6创建相应的部署目录
[root@localhost
tomcat6]#mkdirwebapp
同时将工程发布到的新建的部署目录中
第三步、创建配置文件目录和配置文件
1)进入相应目录
[root@localhosttomcat6]#cd/webapp/tomcat6/conf
2)创建目录
[root@localhostconf]#mkdirCatalinai
3)拷贝配置文件
[root@localhost
conf]#cp-r./Catalina/localhost/./Catalinai
4)验证以上操作的正确性
[root@localhost
conf]#cdCatalinai/
[root@localhostCatalinai]#cdlocalhost/
[root@localhost
localhost]#pwd
/webapp/tomcat6/conf/Catalinai/localhost
[root@localhost
localhost]#ls
host-manager.xmlmanager.xml
第四步、重启tomcat服务并验证相应端口服务已经正常运行
1)lsof
–i:
8080
2)lsof
–i:
8090
如果返回相应java进程则证明配置无误。
二、附tomcat前端Nginx代理相关的调整和配置
##以下为测试环境下Nginx配置文件的详细内容,关键配置点参见蓝色标注的文字亲
userwwwwww;
worker_processes2;error_log
/usr/local/nginx/logs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
pid
/usr/local/nginx/logs/nginx.pid;events{
useepoll;
worker_connections65535;
}
http{
server_tokensoff;
includemime.types;
default_typeapplication/octet-stream;
#include
/usr/local/nginx/conf/proxy.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;
server_names_hash_bucket_size
128;
client_header_buffer_size32k;
large_client_header_buffers8
32k;
#client_max_body_size8m;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
##cache##
proxy_connect_timeout5;
proxy_read_timeout60;
proxy_send_timeout5;
proxy_buffer_size16k;
proxy_buffers464k;
proxy_busy_buffers_size128k;
proxy_temp_file_write_size
128k;
proxy_temp_path
/usr/local/nginx/temp;
proxy_cache_path
/usr/local/nginx/cachelevels=1:
2keys_zone=cache_one:
200minactive=1d
max_size=30g;
##end##
#upstream124.128.153.56{
#serverhttp:
//10.0.211.4/sdws/;
#server
http:
//10.0.211.5/sdws/;
#server
http:
//10.0.211.6/sdws/;
#}
server{
listen80;
server_namelocalhost;
#charsetkoi8-r;
charsetutf-8;
indexindex.htmlindex.htmindex.jsp
login.jsp;
#access_loglogs/host.access.logmain;
root/webapp/tomcat6/webapps/sdmp;
location~.*\.(jsp|do|action)$#设置动态数据的请求url
{
indexindex.jsp;
proxy_passhttp:
//localhost:
8080;#动态请求转向处理
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For
$proxy_add_x_forwarded_for;
}
location
~.*\.(gif|jpg|jpeg|png|bmp|swf|html)$#静态数据保存时效
{
proxy_passhttp:
//localhost:
8080;
proxy_redirectoff;
proxy_set_headerHost
$host;
proxy_cachecache_one;
proxy_cache_valid2003021h;
proxy_cache_valid3011d;
proxy_cache_validany1m;
expires30d;
}
location~.*\.(js|css)?
$#js和css保存时效
{
expires1h;
}
location~(favicon.ico)
{
log_not_foundoff;
expires30d;
break;
}
location/status#统计Nginx运行状态
{
stub_statuson;
access_log
/usr/local/nginx/logs/status.log;
auth_basic"NginxStatus";
allow10.0.209.0/24;
denyall;
}
#location/{
#root
html;
#index
index.htmlindex.htm;
#}
error_page404/404.html;
#redirectservererror
pagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
#proxythePHPscriptsto
Apachelisteningon127.0.0.1:
80
#
#location~\.php${
#proxy_pass
http:
//127.0.0.1;
#}
#passthePHPscriptsto
FastCGIserverlisteningon127.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.htaccess
files,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#deny
all;
#}
}##addbyfengzhanhai3qiwangluotai
server{
listen81;
server_namelocalhost;
#charsetkoi8-r;
charsetutf-8;
indexindex.htmlindex.htmindex.jsp
login.jsp;
#access_loglogs/host.access.logmain;
root/webapp/tomcat6/webapp/mbp/;
location~.*\.(jsp|do|action)$#设置动态数据的请求url
{
indexindex.jsp;
#root/webapp/tomcat6/webapps/mbp/;
proxy_passhttp:
//localhost:
8090;#动态请求转向处理
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For
$proxy_add_x_forwarded_for;
}
location
~.*\.(gif|jpg|jpeg|png|bmp|swf|html)$#静态数据保存时效
{
proxy_passhttp:
//localhost:
8090;
#root
/webapp/tomcat6/webapps/mbp/;
proxy_redirectoff;
proxy_set_headerHost$host;
proxy_cachecache_one;
proxy_cache_valid2003021h;
proxy_cache_valid3011d;
proxy_cache_validany1m;
expires30d;
}
location~.*\.(js|css)?
$#js和css保存时效
{
expires1h;
}
location~(favicon.ico)
{
log_not_foundoff;
expires30d;
break;
}
}
#anothervirtualhostusing
mixofIP-,name-,andport-basedconfiguration
#
#server{
#listen
8000;
#listen
somename:
8080;
#server_name
somenamealiasanother.alias;
#location/{
#root
html;
#index
index.htmlindex.htm;
#}
#}server{
listen82;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
proxy_pass
http:
//127.0.0.1:
8080/sdws/;
proxy_set_header
Host$host;
proxy_set_header
X-Forwarded-For$proxy_add_x_forwarded_for;
}
#error_page404/404.html;
#redirectservererror
pagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
location~
.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
root
/webapp/tomcat6/webapps/sdws;
if(-f$request_filename)
{
expires1d;
break;
}
}
location~.*\.(js|css)$
{
root
/webapp/tomcat6/webapps/;
if(-f$request_filename)
{
expires1d;
break;
}
}
}
####################################################################################
#server{
#listen811;
#server_namelocalhost;
#
##charsetkoi8-r;
#
##access_loglogs/host.access.logmain;
#
#location/{
#proxy_pass
http:
//127.0.0.1:
8080/mbp/;
#proxy_set_header
Host$host;
#proxy_set_headerX-Forwarded-For
$proxy_add_x_forwarded_for;
#}
#
##error_page404/404.html;
#
##redirectservererrorpagestothe
staticpage/50x.html
#
#error_page500502503504/50x.html;
#location=/50x.html{
#root
html;
#}
#location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
#{
#root
/webapp/tomcat6/webapps/mbp;
#if(-f
$request_filename){
#expires1d;
#break;
#}
#}
#location~.*\.(js|css)$
#{
#root
/webapp/tomcat6/webapps/mbp;
#if(-f
$request_filename){
#expires1d;
#break;
#}
#}
#}
#-->
#addbyfengzhanhai
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Nginx Tomcat 多端 口服 配置 实例 分享