這是一篇由?引起的血案

1、問題發現

筆者擁有一個刨根問底的倔脾氣、
因而就一發不可收拾,非要搞明白究竟是怎麼回事。html

環境: nginx做爲代理服務器  SayHelloServletnginx

SayHelloServlet 訪問路徑 sayHello GET方法正則表達式

原始訪問路徑:http://127.0.0.1:8080/app/sayHello?name=ldd服務器

原由:調用一個Servlet 訪問路徑爲 http://127.0.0.1/sayHello?name=ldd
結果:app

HTTP Status 404 - /app/sayHello%3Fname=ldd

type Status report

message /app/sayHello%3Fname=ldd

description The requested resource is not available.

Apache Tomcat/8.0.28

因而,開始了問題剖析。tcp

#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;

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request_uri" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  access;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
	
	upstream app{
		server 127.0.0.1:8080;
		keepalive  1200;
	}
	
    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;
		access_log  logs/host.access.log  access;
        
		 location =/ {
            rewrite ^(.*)$ /app$1 last;
        }
        location / {
            rewrite ^(.*)$ /app$request_uri last;
        }

	location /app {
		    access_log  logs/app.log  access;
			proxy_pass  http://app;
		}
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}
}
nginx.conf

 

若是有如下兩種配置學習

配置1、
location / {
     rewrite ^(.*)$ /app$request_uri last;
}
配置2、
location / {
     rewrite ^(.*)$ /app$1 last;
}

配置三
location / {
     rewrite ^(.*)$ /app$request_uri redirect;
}
配置四
location / {
     rewrite ^(.*)$ /app$request_uri permanent;
}

很奇怪,若使用配置2、3、四則都可以訪問正常;若使用配置一,則會出現上述錯誤。spa

並且,app.log中的日誌代理

 

127.0.0.1 - - [15/Jul/2016:10:19:58 +0800] "/sayHello?name=ldd" 404 1040 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36" "-"

並不會帶/app/。日誌

真是有太多疑問出現了。

2、引經據典

rewrite學習

這裏又須要用到正則表達式的相關知識,不懂的話能夠先學一下。

 

3、最終

最終仍是不可以合理解釋這個問題,先預存在這裏,歡迎你們指教。

相關文章
相關標籤/搜索