nginx常見(jiàn)內(nèi)置變量$uri和$request_uri的使用
這里介紹nginx常見(jiàn)內(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;
}
關(guān)停nginx:nginx -s stop
啟動(dòng)nginx:nginx
分析過(guò)程:通過(guò)nginx日志來(lái)分析得出$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:
訪問(wèn):http://192.168.128.137/test/
$uri:/test/test.html
$request_uri:/test/
案例2:
訪問(wèn):http://192.168.128.137/
$uri:/jiade.html
$request_uri:/
案例3(真實(shí)名字服務(wù)器上不存在res目錄):
訪問(wèn):http://192.168.128.137/res
$uri:/res
$request_uri:/res
從上面三個(gè)案例就可以得出$uri和$request_uri所代表的值。
到此這篇關(guān)于nginx常見(jiàn)內(nèi)置變量$uri和$request_uri的使用的文章就介紹到這了,更多相關(guān)nginx $uri和$request_uri內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
nginx 隱藏版本號(hào)與WEB服務(wù)器信息的解決方法
這篇文章主要介紹了nginx 隱藏版本號(hào)與WEB服務(wù)器信息的解決方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11
nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問(wèn)資源時(shí)出現(xiàn)404
這篇文章主要介紹了nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問(wèn)資源時(shí)出現(xiàn)404,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
Nginx代理proxy pass配置去除前綴的實(shí)現(xiàn)
這篇文章主要介紹了Nginx代理proxy pass配置去除前綴的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Nginx代理WebSocket失敗的完整排查過(guò)程
在開(kāi)發(fā)基于 WebSocket 的實(shí)時(shí)應(yīng)用時(shí),使用 Nginx 作為反向代理是常見(jiàn)做法,可是我遇見(jiàn)了后端直連 WebSocket 成功,通過(guò) Nginx 代理卻失敗,本文將完整復(fù)盤(pán)一次真實(shí)排查過(guò)程,帶你避開(kāi)所有坑,需要的朋友可以參考下2025-11-11
nginx 開(kāi)啟 pathinfo的過(guò)程詳解
這篇文章主要介紹了nginx 開(kāi)啟 pathinfo的過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
nginx status狀態(tài)頁(yè)配置方法和中文說(shuō)明
這篇文章主要介紹了nginx status狀態(tài)頁(yè)配置方法和中文說(shuō)明,重點(diǎn)在配置例子和status的中文說(shuō)明,需要的朋友可以參考下2014-06-06

