我的网络环境是这样的: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/ target=_blank class=infotextkey>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; } } (责任编辑:IT) |