nginx常見內(nèi)置變量$uri和$request_uri的使用
這里介紹nginx常見內(nèi)置變量$uri和$request_uri代表的值,首先先看nginx配置:
[root@CentOS7-2 conf.d]# cat /etc/nginx/conf.d/default.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; # index index.html index.htm; index jiade.html index.html; } location /test { root /usr/share/nginx/html; index test.html; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
配置log形式和保存路徑:
[root@CentOS7-2 nginx]# cat /etc/nginx/nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; #配置nginx使用epoll I/O模型 use epoll ; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$uri --- $request_uri -- $remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
關停nginx:nginx -s stop
啟動nginx:nginx
分析過程:通過nginx日志來分析得出$uri和$request_uri值
[root@CentOS7-2 nginx]# tail -200f /var/log/nginx/access.log /test/test.html --- /test/ -- 192.168.128.1 - - [31/Dec/2019:08:54:43 +0800] "GET /test/ HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-" /favicon.ico --- /favicon.ico -- 192.168.128.1 - - [31/Dec/2019:08:57:16 +0800] "GET /favicon.ico HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" "-" /jiade.html --- / -- 192.168.128.1 - - [31/Dec/2019:08:57:18 +0800] "GET / HTTP/1.1" 200 6 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-" /favicon.ico --- /favicon.ico -- 192.168.128.1 - - [31/Dec/2019:08:57:19 +0800] "GET /favicon.ico HTTP/1.1" 404 555 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)" "-" /res --- /res -- 192.168.128.1 - - [31/Dec/2019:08:58:34 +0800] "GET /res HTTP/1.1" 404 153 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-" /favicon.ico --- /favicon.ico -- 192.168.128.1 - - [31/Dec/2019:08:58:34 +0800] "GET /favicon.ico HTTP/1.1" 404 555 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)" "-" /jiade.html --- / -- 192.168.128.1 - - [31/Dec/2019:09:02:09 +0800] "GET / HTTP/1.1" 200 6 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-" /favicon.ico --- /favicon.ico -- 192.168.128.1 - - [31/Dec/2019:09:02:09 +0800] "GET /favicon.ico HTTP/1.1" 404 555 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)" "-"
案例1:
訪問:http://192.168.128.137/test/
$uri:/test/test.html
$request_uri:/test/
案例2:
訪問:http://192.168.128.137/
$uri:/jiade.html
$request_uri:/
案例3(真實名字服務器上不存在res目錄):
訪問:http://192.168.128.137/res
$uri:/res
$request_uri:/res
從上面三個案例就可以得出$uri和$request_uri所代表的值。
到此這篇關于nginx常見內(nèi)置變量$uri和$request_uri的使用的文章就介紹到這了,更多相關nginx $uri和$request_uri內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Nginx配置多個端口進行監(jiān)聽的實現(xiàn)
隨著容器的應用越來越多,將nginx部署在容器中也是常有之事,本文主要介紹了Nginx配置多個端口進行監(jiān)聽的實現(xiàn),文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧2024-07-07nginx 網(wǎng)頁匹配跳轉rewrite、location的具體使用
本文主要介紹了nginx 網(wǎng)頁匹配跳轉rewrite、location的具體使用2024-05-05nginx提示:500 Internal Server Error錯誤的解決方法
本文章來給大家總結了大量關于導致nginx中提示500 Internal Server Error錯誤的原因總結與解決方法分析有需要了解的朋友可參考參考2013-04-04nginx禁止直接通過ip進行訪問并跳轉到自定義500頁面的操作
這篇文章主要介紹了nginx禁止直接通過ip進行訪問并跳轉到自定義500頁面的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05Nginx重定向后請求參數(shù)丟失的原因分析及解決方案
在日常開發(fā)和運維中,我們經(jīng)常會遇到需要使用 Nginx 進行反向代理的場景,但在配置 proxy_pass 時,有時候可能會遇到請求參數(shù)丟失的問題,在這篇文章中,我們將會詳細探討這個問題并給出幾種解決方案,需要的朋友可以參考下2023-11-11nginx轉發(fā)內(nèi)網(wǎng)圖片的代碼示例
這篇文章主要給大家介紹了nginx轉發(fā)內(nèi)網(wǎng)圖片,文章通過代碼示例介紹的非常詳細,對大家的學習或工作有一定的幫助,感興趣的小伙伴可以自己動手試一下2023-10-10Nginx出現(xiàn)The plain HTTP request was sent to HTTPS port問題解決方法
這篇文章主要介紹了Nginx出現(xiàn)The plain HTTP request was sent to HTTPS port問題解決方法,需要的朋友可以參考下2015-04-04Nginx+keepalived實現(xiàn)七層的負載均衡的高可用(最新解決方案)
這篇文章主要介紹了Nginx+keepalived實現(xiàn)七層的負載均衡的高可用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-03-03