nginx 服务器访问很慢

各位大佬:

 我的网络环境是这样的:nginx+tomcat 2个  其端口都受公司网关防火墙控制,现在公司的网关防火墙(以下简称防火墙)只开放了80端口,而后面tomcat的端口808和8080都没有开放。

问题:访问nginx很慢。。

1、我在公司网关防火墙开放了其中的一个tomcat端口808时,访问还是很慢。俩tomcat端口都开放时,访问很快。当我在防火墙开放一个tomcat端口808,而关闭另一个8080端口的tomcat时,就访问很快。。

2、有,当我把程序中的.jsp文件中<base href= <%=basePath%> >这一行给注释掉时,访问也很快。。

我对于nginx反向代理的理解是: nginx在接收到客户端的请求后,通过http请求,直接根据负载均衡策略将请求分派到某一个tomcat。这是一个内部的通讯。我感觉不需要走外网,或者出现像上面1中所那样的情况。但事实是,我还得在防火墙中开放两个tomcat的端口,才能实现正常访问。。

操作到这里,我有些迷糊,搞不大明白了。。请帮忙!先谢过。。

下面是我的nginx配置:

#user www www;
worker_processes 5;
error_log logs/nginx_error.log crit;
pid        /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{

include       mime.types;
include       /usr/local/nginx/conf/proxy.conf;
default_type application/octet-stream;
#charset gb2312;
charset UTF-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
#client_max_body_size 20m;
limit_rate 1024k;
sendfile on;
tcp_nopush     on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
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;
#limit_zone crawler $binary_remote_addr 10m;
proxy_temp_path /usr/local/proxy_temp_dir;
proxy_cache_path /usr/local/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
upstream tomcat-servers {
   ip_hash;
   server 10.10.10.16:8080 ;
   server 10.10.10.16:808 ;
#   server 10.10.10.16:9090 weight=1;
}

server
{
   listen       80;
   server_name  localhost;
   index index.html index.htm index.jsp;
   root /var/lib/tomcat/webapps;
   #location ~ .*\.jsp$
   # location ~ .*.(jsp|do|action)$ #所有jsp的页面均交由tomcat处理
   location /
   {
     proxy_pass http://tomcat-servers;
     proxy_redirect    off;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header Host $http_host;
 proxy_next_upstream http_502 http_504 error timeout invalid_header;
   }
      location ~ ^/(images|javascript|js|css|flash|media|static)/ {
        root /var/lib/tomcat/webapps;
        expires 30d;
    }

 
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
             proxy_pass http://tomcat-servers;
              proxy_redirect off;
              proxy_set_header Host $host;
              proxy_cache cache_one;
              proxy_cache_valid 200 302 1h;
              proxy_cache_valid 301 1d;
              proxy_cache_valid any 1m;
              expires      30d;
   }
   location ~ .*\.(js|css)?$
   {
     expires      1h;
   }
   location /Nginxstatus {
    
     stub_status on;
     access_log   off;
   }
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
# access_log off;
}
}

转载于:https://my.oschina.net/u/159419/blog/28676

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值