windows下nginxHTTP伺服器入門教程初級篇

來源:互聯網
上載者:User

一、介紹Nginx是俄羅斯人編寫的十分輕量級的HTTP伺服器,Nginx,它的發音為“engine X”, 是一個高效能的HTTP和反向 Proxy伺服器,同時也是一個IMAP/POP3/SMTP Proxy 伺服器.
二、Location文法文法:location [=|~|~*|^~] /uri/ { … }
註:
1、~ 為區分大小寫匹配
2、~* 為不區分大小寫匹配
3、!~和!~*分別為區分大小寫不匹配及不區分大小寫不匹配
樣本一:
location / { }
匹配任何查詢,因為所有請求都以 / 開頭。但是Regex規則將被優先和查詢匹配。
樣本二:
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 !~ "^star\.igrow\.cn$&quot [點擊圖片可在新視窗開啟] {
rewrite ^(.*) http://star.igrow.cn$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/linuxtone/test;
deny all;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.