国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

Nginx Location 語法,與簡單配置

2024-08-30 12:06:31
字體:
來源:轉載
供稿:網友

一、介紹Nginx是俄羅斯人編寫的十分輕量級的HTTP服務器,Nginx,它的發音為“engine X”, 是一個高性能的HTTP和反向代理服務器,同時也是一個IMAP/POP3/SMTP 代理服務器.
二、Location語法語法:location [=|~|~*|^~] /uri/ { … }
注:
1、~   為區分大小寫匹配
2、~* 為不區分大小寫匹配
3、!~和!~*分別為區分大小寫不匹配及不區分大小寫
不匹配
示例一:
location  / {
}
匹配任何查詢,因為所有請求都以 / 開頭。但是正則表達式規則將被優先和查詢匹配。
示例二:
location =/ {}
僅僅匹配/

示例三:
location ~* /.(gif|jpg|jpeg)$ {
rewrite /.(gif|jpg)$ /logo.png;

注:不區分大小寫匹配任何以gif,jpg,jpeg結尾的文件

三、ReWrite語法
last - 基本上都用這個Flag。
break - 中止Rewirte,不在繼續匹配
redirect - 返回臨時重定向的HTTP狀態302
permanent - 返回永久重定向的HTTP狀態301

1、下面是可以用來判斷的表達式:
-f和!-f用來判斷是否存在文件
-d和!-d用來判斷是否存在目錄
-e和!-e用來判斷是否存在文件或目錄
-x和!-x用來判斷文件是否可執行
2、下面是可以用作判斷的全局變量
例:http://localhost:88/test1/test2/test.php
$host:localhost
$server_port:88
$request_uri:
http://localhost:88/test1/test2/test.php
$document_uri:/test1/test2/test.php
$document_root:D:/nginx/html
$request_filename:D:/nginx/html/test1/test2/test.php

四、Redirect語法
    server {
    listen 80;
    server_name start.igrow.cn;
    index index.html index.php;
    root html;
    if ($http_host !~ "^www/.VeVb/.com$ {
         rewrite ^(.*)
http://m.survivalescaperooms.com$1 redirect;
    }
    }

五、防盜鏈location ~* /.(gif|jpg|swf)$ {
  valid_referers none blocked start.igrow.cn sta.igrow.cn;
  if ($invalid_referer) {
  rewrite ^/
http://$host/logo.png;
  }
}

六、根據文件類型設置過期時間
location ~* /.(js|css|jpg|jpeg|gif|png|swf)$ {
if (-f $request_filename) {
   expires    1h;
   break;
}
}

七、禁止訪問某個目錄
location ~* /.(txt|doc)${
   
  root /data/www/wwwroot/linuxtone/test;
   
deny all;
}
 

++ 一些可用的全局變量
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平远县| 彭山县| 都匀市| 乌拉特中旗| 墨竹工卡县| 临泉县| 新巴尔虎右旗| 广昌县| 米林县| 香格里拉县| 张家界市| 额敏县| 宁明县| 渑池县| 武鸣县| 五华县| 汉沽区| 河津市| 广河县| 文山县| 双鸭山市| 西藏| 林口县| 宁南县| 东光县| 内黄县| 和硕县| 保康县| 收藏| 湾仔区| 隆尧县| 凉山| 阿尔山市| 霍林郭勒市| 阿合奇县| 双城市| 彭山县| 英德市| 若羌县| 巴青县| 潢川县|