nginx tomcat代理返回一个不正确的url

时间:2015-05-19 16:37:40

标签: tomcat nginx

我已经请求了像index.jsp这样的jsp。 jsp中有一些链接

<a href="/test/a.jsp">A</a>
<a href="/test/b.jsp">B</a>

但点击了A标记后,我收到了一个不正确的网址,例如“http://tomcat_server/test/a.jsp”。

  1. [tomcat_server]是在nginx中配置的tomcat代理名称。

  2. [test]是在tomcat中部署的Web项目名称。

  3. 以下代码是我的nginx配置。

    nginx.conf

    #user  nobody;                          
    worker_processes  auto;         
    worker_cpu_affinity auto;
    
    error_log  /opt/logs/nginx/nginx_error.log  error;      
    
    pid        /dev/shm/nginx.pid;          
    
    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 51200;
    
    dso {
         load ngx_http_footer_filter_module.so;
         load ngx_http_limit_conn_module.so;
         load ngx_http_limit_req_module.so;
         load ngx_http_sysguard_module.so;
         load ngx_http_upstream_ip_hash_module.so;
         load ngx_http_upstream_least_conn_module.so;
         load ngx_http_upstream_session_sticky_module.so;
    }
    
    events {
            use epoll;                                      
        worker_connections  51200;      
    }
    
    
    http {
        include       mime.types;                                       
        default_type  application/octet-stream;
        charset  utf-8;    
    
        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" $http_x_forwarded_for';             
    
        open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m;
    
    
        server_names_hash_bucket_size 256;    
        client_header_buffer_size 256k;      
        large_client_header_buffers 4 256k;  
    
    
        #size limits
        client_max_body_size          50m;      
        client_header_timeout         3m;       
        client_body_timeout           3m;      
        send_timeout                  3m;      
        sendfile                      on;      
        tcp_nopush                    on;      
        keepalive_timeout             60;      
        tcp_nodelay                   on;      
        server_tokens                 on;      
    
        server_name_in_redirect off;
        server_info off;        
        server_tag off;     
    
        limit_req_log_level error; 
        limit_conn_zone $binary_remote_addr zone=perip:10m; 
        limit_req_zone $binary_remote_addr zone=one:30m rate=10r/s;
    
    
    
        include  gzip.conf;                     
        include  proxy.conf;                    
        include  vhost/*.conf;                  
        include  mysvrhost.conf;               
    
    
    }
    

    proxy.conf

    proxy_temp_path   /dev/shm/nginx/proxy_temp;
    
    proxy_cache_path  /dev/shm/nginx/proxy_cache levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=30g;
    
    client_body_buffer_size  512k;     
    proxy_connect_timeout    50;       
    proxy_read_timeout       600;      
    proxy_send_timeout       600;      
    proxy_buffer_size        128k;     
    proxy_buffers           16 256k;   
    proxy_busy_buffers_size 512k;      
    proxy_temp_file_write_size 1024m;  
    #proxy_ignore_client_abort  on;    
    
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404 http_502 http_504;
    

    mysvrhost.conf

    upstream tomcat_server {
     server 127.0.0.1:18080;
    }
    

    tomcat1.conf [在vhost目录下]

    server {
            listen 80;
            server_name localhost;
    
            index index.html index.htm;
    
            root /opt/tomcat/webapps;
    
            access_log  /opt/logs/nginx/localhost.log  access buffer=24k;
    
    
    
            limit_req zone=one burst=50;
            limit_conn perip 50;
    
            if (-d $request_filename){
                #rewrite http://$host/aa.jsp permanent;
                rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
            }
    
            location ~ ^/(WEB-INF)/ {
                    deny all;
            }
    
        location ~ /purge(/.*) {
                  allow           all;
                 allow            127.0.0.1;
                 allow            192.168.0.0/16;
                 #deny             all;
                 proxy_cache_purge    cache_one   $host$1$is_args$args;
                 error_page 405 =200 /purge$1;          
                }  
               if ( $request_method = "PURGE" ) {
                 rewrite ^(.*)$ /purge$1 last;
                } 
    
    
            location ~ 404\.html$ {
                root /opt/tomcat/webapps;            
                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_pass http://tomcat_server;
                add_header      X-Cache   Cache-Skip;
                expires 3d;
        }
    
            location ~ .*/(upload)/ {
                root         /opt/tomcat/webapps/upload;
                    access_log   off;
            }
    
    
            location ~ .*\.(html)?$  {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
                 proxy_cache cache_one;
    
                 root /opt/tomcat/webapps;                           
                proxy_cache_valid  200 304 12h;
    
                 proxy_cache_key $host$uri$is_args$args;
                 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_ignore_headers "Cache-Control" "Expires";
                 add_header      X-Cache   Cache;
            }
    
            location ~* ^.+\.(png|jpg|jpeg|gif|png|rar|zip|css|js|woff|ttf|svg)$ {
    
                root /opt/tomcat/webapps;
                access_log   off;
    
                 proxy_next_upstream http_502 http_504 error timeout invalid_header;
                 proxy_cache cache_one;
    
                 proxy_cache_valid  200 304 12h;
    
                  proxy_cache_key $host$uri$is_args$args;
                 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_ignore_headers "Cache-Control" "Expires";
                 add_header      X-Cache   Cache;
            }
    
             location ~ .*\.(htm|do|action|jsp)?$  {
                 proxy_next_upstream http_502 http_504 error timeout invalid_header;
                 proxy_cache cache_one;                  
                 proxy_pass http://tomcat_server;
            }
    
             location /  {
                proxy_next_upstream http_502 http_504 error timeout invalid_header;
                 proxy_cache cache_one;                  
                 proxy_pass http://tomcat_server;
            }   
    
            location /NginxStatus {
                stub_status on;
                access_log off;
                auth_basic "NginxStatus";
            }
    
    
            error_page 404 /404.html;
            error_page 500 502 503 504 /404.html;
    
    
    }
    

    我不熟悉nginx.I无法修复错误配置的位置。

    非常感谢任何对此的帮助,谢谢!

0 个答案:

没有答案