国产探花免费观看_亚洲丰满少妇自慰呻吟_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://www.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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大余县| 孝昌县| 白朗县| 四会市| 灵宝市| 宁南县| 汕尾市| 廊坊市| 义马市| 梅河口市| 林西县| 绍兴县| 临沂市| 黄大仙区| 六安市| 神农架林区| 丰宁| 汉阴县| 木里| 五华县| 丰县| 从化市| 星子县| 乌鲁木齐市| 尼木县| 仙居县| 安乡县| 申扎县| 海南省| 得荣县| 崇信县| 衡山县| 隆回县| 肇庆市| 朝阳县| 鹰潭市| 东平县| 偃师市| 麻江县| 台东市| 阿勒泰市|