系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 系统教程 > 系统帮助 > 详细页面

nginx 基础模块 2 虚拟机location等

时间:2020-02-23来源:电脑系统城作者:电脑系统城

一 虚拟主机

server {
        listen       80;
        server_name  www.yang.com;
        #虚拟机主机重点,一样的ip端口,虚拟机主机就是靠这边的域名来路由内容的
        root         /yang/;
        #根目录 
        index index.html index.php;
        access_log  /yang/yang_com_access.log  main;

        location / {
        }
}   

#虚拟机主机只需要在conf.d目录里 另起一个.conf 文件,里面把server段配好就行了,如果是相同ip端口 用域名来区分,就像上面代码一样

二 日志

nginx 基础模块 2 虚拟机location等
#这些字段是控制日志输出内容的

$remote_addr变量:记录了客户端的IP地址(普通情况下)。
$remote_user变量:当nginx开启了用户认证功能后,此变量记录了客户端使用了哪个用户进行了认证。
$time_local变量:记录了当前日志条目的时间。
$request变量:记录了当前http请求的方法、url和http协议版本。
$status变量:记录了当前http请求的响应状态,即响应的状态码,比如200、404等响应码,都记录在此变量中。
$body_bytes_sent变量:记录了nginx响应客户端请求时,发送到客户端的字节数,不包含响应头的大小。
$http_referer变量:记录了当前请求是从哪个页面过来的,比如你点了A页面中的超链接才产生了这个请求,那么此变量中就记录了A页面的url。
$http_user_agent变量:记录了客户端的软件信息,比如,浏览器的名称和版本号。

nginx 基础模块 2 虚拟机location等
#设置访问日志的存储路径,error_log 是设置错误日志的

三.location

优先级

=    精确匹配:用于标准uri前,要求请求字符串和uri严格匹配。如果匹配成功就停止匹配,立即执行该location里面的请求。
~    正则匹配:用于正则uri前,表示uri里面包含正则,并且区分大小写。
~*  正则匹配:用于正则uri前,表示uri里面包含正则,不区分大小写。
^~  非正则匹配;用于标准uri前,nginx服务器匹配到前缀最多的uri后就结束,该模式匹配成功后,不会使用正则匹配。
无    普通匹配(\);与location顺序无关,是按照匹配的长短来取匹配结果。若完全匹配,就停止匹配。
PS: 优先级从高到低

1 “=”精准匹配

location = /news/ {
            echo "test1";
        }
[root@www quail]# curl 192.168.249.132/news/
test1

2 "~"区分大小写正则匹配

location ~ \.(html) {
    echo 'test2';
}
location ~ \.(htmL) {
    echo 'test3';
}
[root@www quail]# curl 192.168.249.132/index.html
test2
[root@www quail]# curl 192.168.249.132/index.htmL
test3

3 “~*”不区分大小写的正则匹配

location ~* \.(html){
            echo 'test4';
}
[root@www quail]# curl 192.168.249.132/index.htmL
test4
[root@www quail]# curl 192.168.249.132/index.html
test4

4 “^~”不进行正则匹配的标准匹配,只匹配前缀

location ^~ /index/ {
            echo 'test5';
}
[root@www quail]# curl 192.168.249.132/index/
test5
[root@www quail]# curl 192.168.249.132/index/heihei
test5
[root@www quail]# curl 192.168.249.132/index/asdnmkalsjd
test5

5 普通匹配

location / {
            echo 'test6';
}
[root@www quail]# curl 192.168.249.132
test6
分享到:

相关信息

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载