1. 程式人生 > 實用技巧 >一、【pytest實戰--Web測試】搭建環境

一、【pytest實戰--Web測試】搭建環境

location 指令說明

location [ = | ~ | ~* | ^~ ] uri {

}
  1. = :用於不含正則表示式的 uri 前,要求請求字串與 uri 嚴格匹配,如果匹配成功,就停止繼續向下搜尋並立即處理該請求。
  2. ~ :用於表示 uri 包含正則表示式,並且區分大小寫。
  3. ~* :用於表示 uri 包含正則表示式,並且不區分大小寫。
  4. ^~ :用於不含正則表示式的 uri 前,要求 Nginx 伺服器找到標識 uri 和請求字串匹配度最高的 location 後,立即使用此 location 處理請求,而不再使用 location 塊中的正則 uri 和請求字串做匹配。

注意:如果 uri 包含正則表示式,則必須要有 ~ 或者 ~* 標識。

192.168.0.107:80 ->127.0.0.1:8080

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  192.168.0.107;
		
        location / {
	    proxy_pass   http://127.0.0.1:8080;
        }
    }
}

http://192.168.0.107:9001/docs/ ->127.0.0.1:8080

http://192.168.0.107:9001/examples/ ->127.0.0.1:8081

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       9001;
        server_name  192.168.0.107;
		
	location / {
            root   html;
            index  index.html index.htm;
        }
		
        location ~ /docs/ {
	    proxy_pass   http://127.0.0.1:8080;
        }
		
	location ~ /examples/ {
	    proxy_pass   http://127.0.0.1:8081;
        }
    }
}


https://nginx.org/en/docs/http/ngx_http_core_module.html#location