亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

安全服務器是只允許所需數量的服務器。理想情況下,我們將通過單獨啟用其他功能來基于最小系統構建服務器。進行最少的配置也有助于調試。如果該錯誤在最小系統中不可用,則分別添加功能,然后繼續搜索錯誤。

這是運行Nginx所需的最低配置:

# /etc/nginx/nginx.confevents {}        
# event context have to be defined to consider config valid
http {}
 server {
    listen 80;
    server_name  JAVAtpoint.co  www.javatpoint.co  *.javatpoint.co;

    return 200 "Hello";
  }

Root,Location和try_files指令

Root 指令

root指令用于設置請求的根目錄,從而允許nginx將傳入的請求映射到文件系統上。

server {
  listen 80;
  server_name javatpoint.co;
  root /var/www/javatpoint.co;
}

它允許nginx根據請求返回服務器內容:

javatpoint.co:80/index.html     # returns /var/www/learnfk.com/index.html
javatpoint.co:80/foo/index.html # returns /var/www/learnfk.com/foo/index.html

Location指令

location指令用于根據請求的URI(統一資源標識符)來設置配置。

語法為:

location [modifier] path

示例:

location /foo {  # ...}

如果未指定修飾符,則將路徑視為前綴,之后可以跟隨任何內容。上面的示例將匹配:

/foo
/fooo
/foo123
/foo/bar/index.html...

我們還可以在給定的上下文中使用多個location指令:

server {
  listen 80;
  server_name javatpoint.co;
  root /var/www/javatpoint.co;

  location/{
    return 200 "root";
  }

  location /foo {
    return 200 "foo";
  }
}
javatpoint.co:80  /      # => "root"
javatpoint.co:80   /foo    # => "foo"
javatpoint.co:80   /foo123 # => "foo"
javatpoint.co:80   /bar    # => "root"

Nginx還提供了一些可以與 location 指令結合使用的修飾符。

修飾符已分配優先級:

=           - Exact match
^~          - Preferential match
~ && ~*     - Regex match
no modifier - Prefix match

首先,nginx將檢查所有精確匹配項。如果不存在,它將尋找優先選項。如果此匹配也失敗,則將按其出現順序測試正則表達式匹配。如果其他所有操作均失敗,則將使用最后一個前綴匹配。

location /match {
  return 200 'Prefix match: will match everything that starting with /match';
}

location ~* /match[0-9] {
  return 200 'Case insensitive regex match';
}

location ~ /MATCH[0-9] {
  return 200 'Case sensitive regex match';
}

location ^~ /match0 {
  return 200 'Preferential match';
}

location = /match {
  return 200 'Exact match';
}
/match     # => 'Exact match'
/match0    # => 'Preferential match'
/match1    # => 'Case insensitive regex match'
/MATCH1    # => 'Case sensitive regex match'
/match-abc # => 'Prefix match: matches everything that starting with /match'

try_files指令

該指令嘗試不同的路徑,并返回找到的任何路徑。

try_files $uri index.html =404;

因此,/foo.html將嘗試按以下順序返回文件:

$uri(/foo.html);

index.html

如果未找到:404

如果我們在服務器上下文中定義try_files,然后定義查找所有請求的位置,則不會執行try_files。發生這種情況是因為服務器上下文中的try_files定義了其偽位置,該偽位置是可能的最低特定位置。因此,定義location/ 會比我們的偽位置更具體。

server {  
try_files $uri /index.html =404;  
location/{ 
 }
}

因此,我們應該避免在服務器上下文中使用try_files:

server {  
location/{   
 try_files $uri /index.html =404; 
 }
}

如里需要學習更多關于nginx的知識體系,也可以關注小編,持續更新。

分享到:
標簽:Nginx
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定