nginx代理tomcat下访问慢

change_solider 发布于 2015/11/30 09:42
阅读 1K+
收藏 0

我在tomcat下放了一个jenkins.war,启动tomcat, 可以正常访问jenkins,不慢。

现在我想使用nginx代理tomcat,当访问http://localhost/jenkins/的时候,自动转向hppt://locahost:8080/jenkins/ ,

出现的问题:访问太慢太慢了。可以排除是tomcat的问题。应该是nginx配置的问题。

nginx配置文件如下:


#user  nobody;
worker_processes  1;


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    #server_names_hash_bucket_size 64;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';


    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;


    #开启压缩功能,节省带宽,提高响应,但是会占CPU
    gzip              on;
    gzip_min_length      1000;
    #压缩指定的文件类型
    gzip_types        text/plain text/css application/x-javascript;


    large_client_header_buffers 4 16k;
    client_max_body_size    50m;
    client_body_buffer_size 256k;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    proxy_connect_timeout   300s;
    proxy_send_timeout      300s;
    proxy_read_timeout      300s;
    proxy_buffer_size       64k;
    proxy_buffers           4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 128k;
    proxy_ignore_client_abort on;
    server {
        listen       80 ;
        server_name  127.0.0.1;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location /jenkins {
            #代理到本机上的8080端口,没有做负载
            proxy_pass http://localhost:8080;
            proxy_redirect          off;
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
           root   html;
        }
    }
}

是不是我的location配置错了?还是proxy配置错了。

报错信息如下

2015/11/30 10:00:32 [error] 2688#4960: *89 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "POST /jenkins/ajaxExecutors HTTP/1.1", upstream: "http://[::1]:8080/jenkins/ajaxExecutors", host: "localhost", referrer: "http://localhost/jenkins/"

部门请求资源会报这个错误。


加载中
0
change_solider
change_solider


#user  nobody;
worker_processes  1;


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


#pid        logs/nginx.pid;




events {
    worker_connections  1024;
}




http {
    include       mime.types;
    default_type  application/octet-stream;
    #server_names_hash_bucket_size 64;


    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';


    #access_log  logs/access.log  main;


    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #开启压缩功能,节省带宽,提高响应,但是会占CPU
    gzip              on;
    gzip_min_length      1000;
    #压缩指定的文件类型
    gzip_types        text/plain text/css application/x-javascript;


upstream jenkins  {
server 127.0.0.1:8080; 
}


upstream solr  {
server 127.0.0.1:8080; 
}






server {


listen       80 ;
server_name  127.0.0.1;


#charset koi8-r;


#access_log  logs/host.access.log  main;


large_client_header_buffers 4 16k;
client_max_body_size    50m;
client_body_buffer_size 256k;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;






location /nginx {
root html;
index index.html;
}





location /solr {
proxy_pass http://solr;
proxy_redirect          off;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout   600s;
proxy_send_timeout      600s;
proxy_read_timeout      600s;
proxy_buffer_size       64k;
proxy_buffers           4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 128k;
proxy_ignore_client_abort on;
}


location  /jenkins {
proxy_pass http://jenkins;
proxy_redirect          off;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;


proxy_connect_timeout   600s;
proxy_send_timeout      600s;
proxy_read_timeout      600s;
proxy_buffer_size       64k;
proxy_buffers           4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 128k;
proxy_ignore_client_abort on;
}




error_page   500 502 503 504  /50x.html;
location = /50x.html {
   root   html;
}
}

}


加一下upstram 就好了。很奇怪。

0
MicyToy
MicyToy

看日志是超时。

有防火墙的话,你再看下本地访问8080端口有问题没

你把worker_processes 改成 auto;

是linux服务器吗? 是的话events里面加上use epoll;

change_solider
change_solider
把 proxy_pass http://localhost:8080; 中的localhost改成127.0.0.1就行了。 就是本机测试的。
0
a
astars
设了负载均hen 就好了?
change_solider
change_solider
不用设,将localhost改成 ip地址就好了。
返回顶部
顶部