当前位置:首页 > CN2资讯 > 正文内容

Nginx做tomcat代理nginx 代理

9小时前CN2资讯

系统环境为6.3 64bit 最小化安装

一,编译pcre,也可以用yum安装pcre# tar xf pcre-8.32.tar.gz  # cd pcre-8.32 # ./configure # make && make install 二,编译nginx yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel 1. gzip module requires zlib library
2. rewrite module requires pcre library
3. ssl support requires openssl library#tar xf nginx-1.2.6.tar.gz#cd nginx-1.2.6.tar.gz# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module   --with-pcre --with-http_memcached_module(这个版本已经支持memcached不需要再添加)编译选项说明
--with-http_ssl_module 支持https请求--with-http_flv_module 支持对FLV文件的拖动播放--with-http_stub_status_module 可以后台查看nginx状态--with-http_gzip_static_module  启用压缩
--with-http_rewrite_module  启用支持url重写--with-pcre  启用支持正则表达式#make & make install[root@test1 nginx]#/usr/local/nginx/sbin/nginx sbin/nginx: error while loading shared libraries: .1: cannot open shar[root@test1 nginx]# ldd /usr/local/nginx/sbin/nginx .1 =>  (0x00007fff343ff000).0 => /lib64/.0 (0x00007fdb3c3af000).1 => /lib64/.1 (0x00007fdb3c178000).1 => not found.10 => /usr/lib64/.10 (0x00007fdb3bf1c000)libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fdb3bb82000)libdl.so.2 => /lib64/libdl.so.2 (0x00007fdb3b97d000)libz.so.1 => /lib64/libz.so.1 (0x00007fdb3b767000)libc.so.6 => /lib64/libc.so.6 (0x00007fdb3b3d4000)/lib64/.2 (0x00007fdb3c5d5000) => /lib64/ (0x00007fdb3b171000)libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fdb3af2f000).3 => /lib64/.3 (0x00007fdb3ac50000)libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fdb3aa4b000).3 => /lib64/.3 (0x00007fdb3a81f000).0 => /lib64/.0 (0x00007fdb3a614000).1 => /lib64/.1 (0x00007fdb3a410000).2 => /lib64/.2 (0x00007fdb3a1f6000).1 => /lib64/.1 (0x00007fdb39fd6000)[root@test1 nginx]# find / -name .0.0.1/lib64/.0.0.1[root@test1 nginx]# cd /lib64/[root@test1 lib64]# ll .0  原来.0.0.1的软件链接是.0lrwxrwxrwx. 1 root root 16 Nov 13 03:32 .0 -> .0.0.1重新建立软链接[root@test1 lib64]# ln -s .0.0.1  .1[root@test1 lib64]# /usr/local/nginx/sbin/nginx 启用ngnix[root@test1 ~]# /usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf也可以用这种方式启用nginx,如果不指定默认会找nginx的安装目录下conf下nginx.conf文件。[root@test1 lib64]# setenforce 0[root@test1 lib64]# /etc/init.d/iptables stop打开nginx的默认页面。[root@test1 ~]# /usr/local/nginx/sbin/nginx -t 测试nginx的配置文件nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@test1 ~]# vim /etc/init.d/nginx #/bin/bash# chkconfig: - 85 15# description: The nginx HTTP Server is an efficient and extensible  \#              server implementing the current HTTP standards.NGINX=/usr/local/nginx/sbin/nginxCONF=/usr/local/nginx/conf/nginx.confstart () {$NGINX -tif [ $? -eq 0 ];thenif  $NGINX ;thenecho " nginx start ok......"elseecho "nginx start fail......"fielseexit 1fi}restart () {$NGINX -s stopif [ $? -ne 0 ];thenkillall -9 nginxfi$NGINX -tif [ $? -eq 0 ];thenif $NGINX ;thenecho " nginx restart ok ......"elseecho "nginx restart fail....."fielseexit 2fi}stop () {$NGINX -s stopif [ $? -eq 0 ];thenecho " nginx stop ok......"elsekillall -9 nginxecho " nginx stop ok......"fi}reload () {$NGINX -tif [ $? -eq 0 ];then$NGINX -s reloadecho "nginx reload ok ........"elseexit 3fi}status () {if [ `ps aux |grep  nginx |wc -l` -eq 1 ];thenecho "nginx is stop....."elseecho "nginx is running......."fi}case $1 in start)start;;stop)stop;;restart)restart;;reload)reload;;status)status;;*)echo "Usgage:`basename $0` {start|stop|restart|status}";;esac[root@test1 ~]# chmod +x /etc/init.d/nginx[root@test1 ~]# chkconfig --add nginx[root@test1 ~]# chkconfig nginx on三,配置tomcat[root@test1 ~]# rpm -ivh jdk-7u9-linux-x64.rpm [root@test1 ~]# vim /etc/profile 在export做下列修改和最一行修改ulimitJAVA_HOME=/usr/java/jdk1.7.0_09/CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/libPATH=$PATH:$JAVA_HOME:/binCATALINA_HOME=/usr/local/tomcatexport JAVA_HOME CATALINA_HOMEexport PATH  USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL  HISTTIMEFORMATunset iunset pathmunge  ulimit -SHn 65535[root@test1 ~]# . /etc/profile[root@test1 ~]# java -versionjava version "1.7.0_09"Java(TM) SE Runtime Environment (build 1.7.0_09-b05)Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)[root@test1 ~]# tar xf apache-tomcat-7.0.32.tar.gz -C /usr/local/[root@test1 ~]# cd /usr/local/[root@test1 local]# ln -s apache-tomcat-7.0.32 tomcat[root@test1 local]# cd tomcat/[root@test1 tomcat]# bin/ start打开浏览器测试,tomcat默认监听8080端口。四,整合nginx与tomcat[root@test1 ~]# cd /usr/local/nginx/[root@test1 nginx]# mv conf/nginx.conf conf/nginx.conf.bak[root@test1 nginx]# vim conf/nginx.confuser  nobody;worker_processes  2;error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    use epoll;    worker_connections  65536;}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"';    sendfile        on;    keepalive_timeout  65;    #配置gzip压缩    gzip on;    gzip_min_length 1k;    gzip_buffers     4 16k;    gzip_http_version 1.0;    gzip_comp_level 2;    gzip_types       text/plain application/x-javascript text/css application/xml;    gzip_vary on;     #设置Web缓存区名称为cache_one,内存缓存空间大小为100MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为1GBproxy_cache_path /usr/local/nginx/cache_data levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=1g;upstream 192.168.1.18 {      #ip_hash策略将同一IP的所有请求都转发到同一应用服务器      #ip_hash;      server localhost:8080;}    server {        listen       80;        server_name  192.168.1.18;        index index.jsp        charset utf-8;        location / {            #root   html;            #index  index.jsp;            proxy_pass http://192.168.1.18;            proxy_set_header X-Real-IP $remote_addr;            client_max_body_size 100m;        }        error_page   500 502 503 504  /50x.html;        location ~* \.(gif|jpg|jpeg|png|bmp|html|htm|flv|swf|ico)$ {           proxy_cache cache_one;           proxy_cache_valid 200 302 304 1h;           proxy_cache_key $host$uri$is_args$args;           proxy_pass http://192.168.1.18;           add_header Last-Modified $date_gmt;           add_header Via $server_addr;           expires 30d;        }        location ~ .*\.(js|css)?$        {         proxy_cache cache_one;         proxy_cache_valid 200 302 304 1h;         proxy_cache_key $host$uri$is_args$args;         proxy_pass http://192.168.1.18;         add_header Last-Modified $date_gmt;         add_header Via $server_addr;         expires      1h;         }        #扩展名以.php、.jsp、.cgi结尾的动态应用程序不缓存location ~ .*\.(php|jsp|cgi)?$ {        proxy_set_header Host $host;        proxy_set_header X-Forwarded-For $remote_addr;        proxy_pass http://192.168.1.18;        }}}[root@test1 nginx]# /etc/init.d/nginx reload打开浏览器如下所示表示整合成功五,安装probe监控tomcat状态1、简介psi-probe是lambdaprobe的一个分支版本,用于对Tomcat进行监控,比tomcat的manager强大很多。psi就是一个形如叉子的符号Ψ,希腊字母的第23个字母,用来代表fork。为啥需要分支呢,因为lambdaprobe已经多年没有更新(大致在2006年就停止发布新版本了)。2、下载地址http:///p/psi-probe/downloads/list3、安装1.解压,将probe.war放进webapps目录。2.修改CATALINA_HOME/conf/tomcat-users.xml(权限配置参考如下,由于首先保证可运行,权限没有特别细分,仅供参考)下面的权限从小到大,probeuser,poweruser,poweruserplus,manager。如果配置了manager,全部的权限可以不用配置。下面只是演示如果配置权限。Mangaer权限最大,如果没有需要可以不要配置。<tomcat-users>  <role rolename="probeuser" />  <role rolename="poweruser" />  <role rolename="poweruserplus" />  <role rolename="manager" />  <user username="tomcat" password="tomcat2012" roles="probeuser,poweruser,poweruserplus,manager"/></tomcat-users>4、注意事项1.不要忘记文件中的<!---->,默认是注释的,需要去掉2.tomcat6.0.30以上,角色manager一分为四,manager仍保留但不建议使用,因为那样容易遭到CSRF攻击。详见下面的描述:[xhtml] view plaincopy1 Note that for Tomcat 6.0.30 onwards, the roles required to use the manager application were changed from the single manager role to add the following four roles. (The manager role is still available but should not be used as it avoids the CSRF protection). You will need to assign the role(s) required for the functionality you wish to access.   2   3 manager-gui - allows access to the HTML GUI and the status pages   4 manager-script - allows access to the text interface and the status pages   5 manager-jmx - allows access to the JMX proxy and the status pages   6 manager-status - allows access to the status pages only   7 The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:   8   9 users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.   10 if the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.  如果配置不对,就会出现403的错误,连tomcat的manager都进不了,更不用说probe了。3.lambdaprobe是不支持tomcat6.0.30以上的。所以最好使用psi-probe。4.在配置tomcat-users.xml时,还需要加入poweruser等角色,才可以正常使用,不然也是403Forbidden。5,效果图重启tomcat进入192.168.1.18/probe输入用户名和密码
    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/32183.html

    分享给朋友:

    “ Nginx做tomcat代理nginx 代理” 的相关文章

    比搬瓦工便宜的CN2是什么东西啊!原来这才是性价比之王

    最近,互联网上掀起一股讨论热潮,大家都想知道“比搬瓦工便宜的CN2是什么东西啊!”究竟是什么来头?其实,CN2作为一个新兴的工具或服务,正在以其超高的性价比迅速占领市场。对于经常使用搬瓦工的用户来说,CN2的出现无疑是一个重磅惊喜。搬瓦工是什么?它是一款功能强大的工具,广泛应用于XX领域(如文件传输...

    美国CN2GIA高防:助力企业游戏与网站稳如泰山

    在全球化的商业环境中,一个稳定、快速、安全的服务器是企业或个人站长成功的关键。无论是网站运营、游戏服务器托管,还是电子商务平台,服务器的性能和安全性都直接影响用户体验和业务收入。而在众多服务器解决方案中,美国CN2GIA高防服务器因其卓越的性能和高安全防护能力,成为无数站长和企业的首选。###为什么...

    如何使用一键同步脚本提高自媒体内容发布效率

    一键同步脚本是一种非常实用的自动化工具,现今在很多领域都可以看到它的身影。作为一名热爱分享与创作的人,我发现无论是自媒体内容发布、数据库备份迁移,还是文件同步,这类脚本都能大大简化我的工作流程。它们不仅能提高工作效率,还能减少出错的可能性,实现工作自动化。 一键同步脚本的核心在于其定义。简单来说,这...

    IPv6 测速方法与工具:提升网络体验的技巧

    IPv6 测速的基本概念 IPv6,作为互联网协议的最新版本,让我们在网络世界中畅游无阻。它的推出旨在解决IPv4所面临的地址枯竭问题,推进更加广泛的设备连接。简单来说,IPv6提供了更大的地址空间,能够支持越来越多的设备上线。因为万物互联的时代已经来临,我们的手机、电脑、家居设备甚至汽车都需要连接...

    解决Windows无法使用复制粘贴功能的实用方法

    在计算机使用中,Windows的复制粘贴功能是我们高效工作与学习的得力助手。从文字处理到文件管理,无论是在文档编辑中提取关键信息,还是将图片或文件快速转移到其他地方,复制粘贴都简化了许多操作。它轻松地帮助我们完成任务,节省了宝贵的时间。 我经常在工作中使用复制粘贴,特别是在撰写报告或为项目汇总资料时...

    P100 GPU价格分析及购买指南 - 如何选择性价比最高的GPU

    在如今的计算技术中,P100 GPU扮演了一个至关重要的角色。尤其是对于那些需要进行大量并行计算的任务,比如深度学习、科学模拟和数据分析,P100 GPU是一款极具吸引力的选项。作为NVIDIA推出的高性能计算单元,P100 GPU不仅具备强大的计算能力,还拥有一系列先进的技术规格,使其在行业中脱颖...