第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
2.1 API 接口規(guī)范

Restful 提倡將接口的行為狀態(tài)放到了 Http 的頭部 method 里。對同一個(gè)資源的不同操作,接口 URL 可能是一樣的。行為規(guī)約主要有下面幾項(xiàng):GET查詢資源,不會對資源產(chǎn)生變化的都用 GET。例:查詢慕課網(wǎng) http Wiki 教程的所有小節(jié)列表:GET http://idcbgp.cn/http如果資源查詢的過程需要帶過濾參數(shù),建議使用 URL 參數(shù)的形式:例:查詢慕課網(wǎng) http 小節(jié)中作者是 rj 的文章GET http://idcbgp.cn/http?author=rj例:查詢慕課網(wǎng) http 里面 id = 1 的文章GET http://idcbgp.cn/http/1POST新增某個(gè)資源:POST http://idcbgp.cn/http具體的參數(shù)放請求體中{"title":"restful","author":"rj","content":"xxxxxx"}PUT資源的修改:PUT http://idcbgp.cn/http/{articleId}具體的參數(shù)放請求體中{"title":"restful","author":"rj","content":"xxxxxx"}PATCHPATCH http://idcbgp.cn/http/{articleId}patch 跟 put 都是修改的意思,put 類型的修改請求體中需要包含全量的對象信息,而 patch 只需要帶上要修改的某幾個(gè)對象即可,沒有帶上的參數(shù)就代表不更新,采用原來的值。具體的參數(shù)放請求體中{"title":"aaa"}DELETE刪除資源:DELETE http://idcbgp.cn/http/{articleId}

4. 編輯 spring-mvc.xml

spring-mvc.xml 用來配置與 Spring MVC 相關(guān)的組件信息,用來提供給 web 上下文對象進(jìn)行組件維護(hù)。這些組件包括 Spring MVC 核心組件和用戶控制器組件。<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 啟動注解支持 --> <mvc:annotation-driven/> <!--靜態(tài)資源交給 tomcat default servelt 處理--> <mvc:default-servlet-handler /> <!--掃描組件位置--> <context:component-scan base-package="com.mk.web.action"></context:component-scan> <!-- 視圖解析器 --> <mvc:view-resolvers> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp"></property> <property name="suffix" value=".jsp"></property> </bean> </mvc:view-resolvers></beans>元素解釋說明:mvc:annotation-driven: 啟動注解支持,完全使用 XML 進(jìn)行 Spring MVC 項(xiàng)目維護(hù),并不是很方便。即使在使用 XML 時(shí),建議還是結(jié)合注解一起使用,這也是 Spring MVC 官方建議的;context:component-scan: 指定哪些組件由 Spring MVC 的上下文對象負(fù)責(zé)。除了 Spring MVC 內(nèi)部組件外,再就是用戶控制器;mvc:view-resolvers: 配置具體的視圖解析器。Tips: 映射器、適配器等組件可以不用顯示配置,采用 Spring MVC 默認(rèn)配置即可。

2.2 負(fù)載均衡的hash算法

我們打開 ip_hash 指令的注釋,這個(gè)時(shí)候默認(rèn)是使用客戶端的 ip 地址作為 hash 的 key,然后重啟 Nginx 服務(wù)并進(jìn)行如下的命令行操作:# 使用本機(jī)的ip地址,無論請求多少出,通過hash轉(zhuǎn)發(fā)到的上游服務(wù)器地址都是一致的[shen@shen ~]$ curl http://180.76.152.1138002, server[shen@shen ~]$ curl http://180.76.152.1138002, server[shen@shen ~]$ curl http://180.76.152.1138002, server# 只有換了ip之后,請求轉(zhuǎn)發(fā)的上游地址才可能有變化[shen@shen ~]$ curl -H 'X-Forwarded-For: 111.10.1.3' http://180.76.152.1138000, server[shen@shen ~]$ curl -H 'X-Forwarded-For: 111.10.2.3' http://180.76.152.1138001, server

2. 獲取 URL 相關(guān)參數(shù)

本節(jié)編寫一個(gè) Flask 程序 request-url.py,打印 request 中和 URL 相關(guān)的屬性:from flask import Flaskfrom flask import requestapp = Flask(__name__)def echo(key, value): print('%-10s = %s' % (key, value))@app.route('/query')def query(): echo('url', request.url) echo('base_url', request.base_url) echo('host', request.host) echo('host_url', request.host_url) echo('path', request.path) echo('full_path', request.full_path) return 'hello'if __name__ == '__main__': app.run(port = 80)在瀏覽器中輸入 http://localhost/query?userId=123,程序在終端輸出如下:url = http://localhost/query?userId=123base_url = http://localhost/queryhost = localhosthost_url = http://localhost/path = /queryfull_path = /query?userId=123

2. HTTPS

Https 是一種通過計(jì)算機(jī)網(wǎng)絡(luò)進(jìn)行安全通信的傳輸協(xié)議,經(jīng)由 Http 進(jìn)行通信,利用 SSL/TLS 建立安全信道,加密數(shù)據(jù)包。Https 使用的主要目的是提供對網(wǎng)站服務(wù)器的身份認(rèn)證,同時(shí)保護(hù)交換數(shù)據(jù)的隱私與完整性。Http 服務(wù)的默認(rèn)端口是 80,Https 服務(wù)的默認(rèn)端口是 443。HTTP + SSL = HTTPS = HTTP + 身份認(rèn)證 + 數(shù)據(jù)私密 + 數(shù)據(jù)完整性

4. 小結(jié)

本節(jié)中介紹了 Nginx 的四層反向代理和七層反向代理,并用案例進(jìn)行了演示。剛開始使用時(shí)只是用了 http 指令塊,因?yàn)槭轻槍?http 請求進(jìn)行處理。這進(jìn)行的是四層反向代理。nginx 七層方向代理處理的是 http 請求,對應(yīng)的是 http 協(xié)議。如果只是轉(zhuǎn)發(fā) http 請求,可以簡單使用 proxy_pass 指令即可。這和我們之前簡單的反向代理示例一致。

3. 使用場景及應(yīng)用實(shí)例

超鏈接是文章的資源向?qū)?,包括錨點(diǎn)連接和外部連接,可以幫助讀者快速定位到文章內(nèi)的某個(gè)位置,或者打開外部的某個(gè)資源和網(wǎng)頁。常見的頁內(nèi)錨點(diǎn)超鏈接如文檔目錄等。實(shí)例 5:一個(gè)屬于自己的門戶頁。#### 一個(gè)簡單的個(gè)人門戶- 常用網(wǎng)站 [百度](http://www.baidu.com), [慕課](http://idcbgp.cn), [Github](http://www.github.com)- 新聞 [人民網(wǎng)](http://www.people.com.cn/), [央視網(wǎng)](http://www.cctv.com/), [光明網(wǎng)](http://www.gmw.cn/),- 購物網(wǎng)站 [淘寶](http://www.taobao.com), [京東](http://www.jd.com)- 程序文檔 [小程序開發(fā)文檔](https://developers.weixin.qq.com/miniprogram/dev/framework/)渲染結(jié)果如下:

3.1 下載合適的 USB 驅(qū)動程序

由于不同品牌的手機(jī),USB 驅(qū)動程序也是不同的,所以推薦大家從品牌廠商的官網(wǎng)下載 USB 驅(qū)動程序。設(shè)備制造商驅(qū)動程序網(wǎng)址宏碁http://www.acer.com/worldwide/support/華碩https://www.asus.com/support/Download-Center/BlackBerryhttps://swdownloads.blackberry.com/Downloads/entry.do?code=4EE0932F46276313B51570F46266A608Dellhttp://support.dell.com/support/downloads/index.aspx?c=us&cs=19&l=en&s=dhs&~ck=anavmlFujitsuhttp://www.fmworld.net/product/phone/sp/android/develop/HTChttp://www.htc.com/support華為http://consumer.huawei.com/en/support/index.htmIntelhttp://www.intel.com/software/androidKyocerahttp://www.kyocera-wireless.com/support/phone_drivers.htm聯(lián)想http://support.lenovo.com/us/en/GlobalProductSelectorLGEhttp://www.lg.com/us/support/software-firmwareMotorolahttps://motorola-global-portal.custhelp.com/app/answers/detail/a_id/88481/MTKhttp://online.mediatek.com/Public Documents/MTK_Android_USB_Driver.zipSamsunghttp://developer.samsung.com/galaxy/others/android-usb-driver-for-windows夏普http://k-tai.sharp.co.jp/support/Sonyhttp://developer.sonymobile.com/downloads/drivers/小米http://www.xiaomi.com/c/driver/index.html中興http://support.zte.com.cn/support/news/NewsDetail.aspx?newsId=1000442

2.1 簡單的七層負(fù)載均衡

在 nginx.conf 中添加如下的 http 指令塊:http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; gzip on; server { listen 8000; return 200 '8000, server\n'; } server { listen 8001; return 200 '8001, server\n'; } server { listen 8002; return 200 '8002, server\n'; } upstream backends { # ip_hash # hash user_$arg_username; server 127.0.0.1:8000; server 127.0.0.1:8001; server 127.0.0.1:8002; } server { listen 80; location / { proxy_pass http://backends; proxy_http_version 1.1; proxy_set_header Connection ""; } }}上述配置中,我們用8000,8001和8002三個(gè)端口模擬了3個(gè)上游服務(wù)器,默認(rèn)使用輪詢負(fù)載均衡算法,而且三個(gè)的權(quán)重均為1。進(jìn)行如下的 http 請求操作,可以看到 Nginx 轉(zhuǎn)發(fā) http 請求會均勻地分配到3個(gè)服務(wù)器上。[shen@shen ~]$ curl http://180.76.152.1138000, server[shen@shen ~]$ curl http://180.76.152.1138001, server[shen@shen ~]$ curl http://180.76.152.1138002, server[shen@shen ~]$ curl http://180.76.152.1138000, server

3.2 七層反向代理示例

在 nginx.conf 中加入如下的測配置:...http { server { listen 8000; return 200 '$uri\n'; } server { listen 9001; location /test { proxy_pass http://127.0.0.1; } } server { listen 9002; location /test { proxy_pass http://127.0.0.1/xyz; } }}...啟動 nginx 后,通過請求服務(wù)器的8000端口,我們可以知道請求的 uri 值,然后測試經(jīng)過兩種類型的 proxy_pass 配置后最后的 uri 的值。具體操作以及結(jié)果如下:# 測試8000端口顯示的uri值[shen@shen ~]$ curl http://180.76.152.113:8000/test/abc/test/abc# 9001端口配置中proxy_pass后面的URL不帶URI[shen@shen ~]$ curl http://180.76.152.113:9001/test/abc/test/abc# 9002端口配置中proxy_pass后面的URL帶URI,會替換到匹配的/test[shen@shen ~]$ curl http://180.76.152.113:9002/test/abc/xyz/abc

4. 小結(jié)

本節(jié)講解了 HTTP 協(xié)議中的不同方法,通過一個(gè)具體的例子,講解在 Flask 應(yīng)用中,如何處理指定 HTTP 方法的請求。對常用的 HTTP 方法,使用思維導(dǎo)圖概括如下:

2. 實(shí)現(xiàn)-TCP/IP 協(xié)議

Http 和 TCP/IP 都是協(xié)議,它們的不同之處在于:HTTP 是瀏覽器和后臺服務(wù)之間的語言,而 TCP/IP是電腦之間的語言(相同的語言才能互相理解雙方要表達(dá)的意思)。Http 本身只是約定了傳輸?shù)臅r(shí)候文字要是什么格式,具體文字如何轉(zhuǎn)成物理的高低電平穿越電腦實(shí)現(xiàn)傳輸?shù)倪^程它是不知道的。所以它需要借助專業(yè)的人士 TCP/IP 來處理。TCP/IP 是專門解決主機(jī)之間信息傳輸?shù)模痪窒抻跒?Http 服務(wù),像發(fā)送郵件也有自己的郵件協(xié)議(SMTP),它的底層也需要借助 TCP/IP 來實(shí)現(xiàn)。(TCP/IP是整套完整的網(wǎng)絡(luò)傳輸框架模型,HTTP 也是屬于它里面的應(yīng)用層)。

3.2 使用自定義方法作為表達(dá)式

如果我們需要擴(kuò)展現(xiàn)有的表達(dá)式,我們可以使用 Spring Bean 里的方法。例如,使用自定義 Bean WebSecurity 中的 check 方法:public class WebSecurity { public boolean check(Authentication authentication, HttpServletRequest request) { ... }}我們可以在配置文件中這樣寫:<http> <intercept-url pattern="/user/**" access="@webSecurity.check(authentication,request)"/> ...</http>或者在 Java 中直接加入配置:http .authorizeRequests(authorize -> authorize .antMatchers("/user/**").access("@webSecurity.check(authentication,request)") ... )

1.1 概述

HTTP 協(xié)議是 Hyper Text Transfer Protocol(超文本傳輸協(xié)議)的縮寫, 用于從萬維網(wǎng)(World Wide Web)服務(wù)器傳輸超文本到本地瀏覽器的傳送協(xié)議。HTTP 協(xié)議工作于客戶端-服務(wù)端架構(gòu)為上。瀏覽器作為 HTTP 客戶端通過 URL 向 服務(wù)端發(fā)送請求,服務(wù)端根據(jù)接收到的請求 URL,向客戶端發(fā)送響應(yīng)信息。HTTP 請求-響應(yīng)模型如下所示:

3.1 默認(rèn)的安全頭配置

Spring Security 提供了一系列默認(rèn) Http 安全響應(yīng)頭,我們可以便捷的配置它們。例如,為 X-Frame-Options 指定值 SAMEORIGIN:@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) { http.headers(headers -> headers.frameOptions(frameOptions -> frameOptions.sameOrigin())); }}如果不希望默認(rèn)頭被自動添加,可以通過如下方式配置,例如僅添加 Cache Control 頭:@EnableWebSecuritypublic class WebSecurityConfig extendsWebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http // ... .headers(headers -> headers // 取消自動添加默認(rèn)頭 .defaultsDisabled() // 添加 CacheControl 頭 .cacheControl(withDefaults()) ); }}或者通過以下方式禁用所有 HTTP 安全響應(yīng)頭:@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.headers(headers -> headers.disable()); }}

2.1 SSL

Https 并不是新的一種協(xié)議,它是 Http 協(xié)議的基礎(chǔ)上面封裝了一層 SSL(Secure Socket Layer),Https 底層跟 Http 一樣是經(jīng)由 TCP 通信的。SSL 并不是 Http 特有的,所有應(yīng)用層協(xié)議都可以使用 SSL 進(jìn)行安全通信。

4.2 access_log 指令用法示例

我們只需要在 http 指令塊中配置 log_format 指令和 access_log 指令即可。測試的配置如下:...http { ... log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; # 和上面的日志格式無關(guān) server { listen 8000; return 200 '8000, server\n'; } ...}...log_format 指令是指定打印日志的格式,access_log 指令指定日志輸出的路徑以及指定使用前面定義的日志格式。在配置好日志相關(guān)的指令后,重啟 Nginx,并發(fā)送一個(gè) Http 請求,就可以在對應(yīng)的路徑上看到相關(guān)的日志信息了。# 模擬發(fā)送http請求[shen@shen Desktop]$ curl http://180.76.152.113:80008000, server[shen@shen Desktop]$ curl -H "X-Forwarded-For: 1.1.1.1" http://180.76.152.113:8000# 查看打印的日志,和前面配置的日志格式進(jìn)行對比[root@server nginx]# tail -2 logs/access.log 103.46.244.226 - - [02/Feb/2020:20:52:05 +0800] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"103.46.244.226 - - [02/Feb/2020:20:57:03 +0800] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "1.1.1.1"

2.2 訪問資源的 URI

客戶端可以新增、修改、刪除聯(lián)系人,相應(yīng)的 URI 如下:HTTP 方法行為URIPOST新增聯(lián)系人http://localhost/usersPUT修改 id 為 123 的聯(lián)系人http://localhost/users/123DELETE刪除 id 為 123 的聯(lián)系人http://localhost/users/123

4. 小結(jié)

Http 直接跟 TCP 傳輸層交互,而 Https 多了一層 SSL 協(xié)議,正式這個(gè)協(xié)議讓 Https 有了數(shù)據(jù)加密、身份認(rèn)證的證書和數(shù)據(jù)完整性保護(hù)這些功能。SSL 是獨(dú)立于 HTTP 的協(xié)議,所以不光是 HTTP 協(xié)議,其他運(yùn)行在應(yīng)用層的 SMTP 和 Telnet 等協(xié)議均可配合 SSL 協(xié)議使用??梢哉f SSL 是當(dāng)今世界上應(yīng)用最為廣泛的網(wǎng)絡(luò)安全術(shù)。

4.2. 補(bǔ)充 Spring 的配置文件

配置文件的目的是將我們自定義的實(shí)現(xiàn)類交給 Spring 的容器管理。因?yàn)?Spring 框架核心功能之一就是 IoC 控制反轉(zhuǎn),目的是將對象實(shí)例化的動作交給容器。還記得第一節(jié)介紹的嗎?不記得了?走你,剩下的我們繼續(xù)。最終 Spring 的配置文件如下:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"> <!-- 此標(biāo)簽的作用 是實(shí)例化UserServiceImpl類的實(shí)例 交給 Spring 容器 --> <bean id="userService" class="com.wyan.service.impl.UserServiceImpl"></bean></beans>

2. 幾種常用的客戶端-服務(wù)器消息傳遞方式

http 最常用的協(xié)議,用于客戶端主動向服務(wù)器發(fā)送請求,單向傳遞;ajax HTTP 的擴(kuò)展版,底層還是 HTTP 協(xié)議,只不過客戶端是無刷新的;comet 也是基于 HTTP 封裝的,使用 HTTP 長連接的方式,原理大致是將 HTTP 的timeout 設(shè)置較長,服務(wù)器有數(shù)據(jù)變化時(shí)返回?cái)?shù)據(jù)給客戶端,同時(shí)斷開連接,客戶端處理完數(shù)據(jù)之后重新創(chuàng)建一個(gè) HTTP 長連接,循環(huán)上述操作(這只是其中一種實(shí)現(xiàn)方式);websocket 這是 HTML5 中的新標(biāo)準(zhǔn),基于 socket 的方式實(shí)現(xiàn)客戶端與服務(wù)端雙向通信,需要瀏覽器支持 HTML5;Adobe Flash Socket 這個(gè)也是使用 socket 的方式,需要瀏覽器支持 flash 才行,為了兼容老版本的瀏覽器;ActiveX object 只適用于 IE 瀏覽器;目前尚沒有一種方式能兼容所有的瀏覽器,只能針對軟件的目標(biāo)客戶人群做一定的兼容。sse 服務(wù)端單向推送。

2. HttpUrlConnection 接口

Android 系統(tǒng)為我們提供了 HttpUrlConnection 接口用于實(shí)現(xiàn) Http 請求。自從 Android API9 開始,HttpUrlConnection 就成為了 Android App 推薦使用的內(nèi)置 Http 庫。使用它無需添加任何依賴,打開網(wǎng)絡(luò)權(quán)限:<uses-permission android:name="android.permission.INTERNET" />就可以訪問 Http 資源了,可以說相比第三方框架

4.1 refer 模塊防盜鏈測試

在 nginx.conf 中加入如下防盜配置:...http { ... server { listen 9008; location / { valid_referers none blocked *.domain.pub www.domain.com/nginx server_names ~\.baidu\.; if ($invalid_referer) { return 403; } return 200 "valid\n"; } } ...}...重新加載或者啟動 Nginx 后,我們進(jìn)行如下操作:[shen@shen Desktop]$ curl -H 'referer: http://www.domain.com/test' http://180.76.152.113:9008 <html><head><title>403 Forbidden</title></head><body><center><h1>403 Forbidden</h1></center><hr><center>nginx/1.17.6</center></body></html>[shen@shen Desktop]$ curl -H 'referer: http://www.domain.com/nginx' http://180.76.152.113:9008 valid[shen@shen Desktop]$ curl -H 'referer: ' http://180.76.152.113:9008 valid[shen@shen Desktop]$ curl http://180.76.152.113:9008 valid[shen@shen Desktop]$ curl -H 'referer: http://www.domain.pub/test' http://180.76.152.113:9008 valid第一個(gè) http 請求 referer 的值存在,但是沒有匹配后面的域名,所以返回403。其余的請求中 referer 值要么不存在,要么沒有這個(gè)頭部,要么匹配了后面的域名正則表達(dá),都通過了 referer 校驗(yàn),所以都返回 “valid” 字符串。我們通過構(gòu)造不同的 referer 頭部字段成功的繞過了 Nginx 的referer 模塊校驗(yàn),也說明了這種防盜的方式極不靠譜。

5. 編輯 application.xml

application.xml 是 Spring 上下文容器所關(guān)聯(lián)的配置文件,可稱其為全局上下文對象的關(guān)聯(lián)配置文件。<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config></context:annotation-config> <context:component-scan base-package="com.mk.web"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan></beans>元素解釋說明:context:annotation-config: 啟動注解支持,建議需要全局上下文對象創(chuàng)建、維護(hù)的對象使用注解的方式;context:component-scan: 掃描位置,需要排除開 Spring MVC 容器對象掃描的位置。Tips: application.xml 文件中一般用來配置業(yè)務(wù)層邏輯組件、數(shù)據(jù)層邏輯組件、通用組件、第三方組件相關(guān)的信息。

3. 小結(jié)

HTTP 協(xié)議應(yīng)該是前端、后端、測試開發(fā)人員最常接觸的網(wǎng)絡(luò)協(xié)議了,因?yàn)檫@是網(wǎng)站和用戶之間傳輸信息的直接渠道。面試官考察 HTTP 相關(guān)的問題,也是為了了解候選人的開發(fā)基本功,為了熟悉本小結(jié)的知識,大家也可以了解下發(fā)送 HTTP 的 Postman 開發(fā)工具,以及 HTTP 網(wǎng)絡(luò)抓包的 Wireshark 工具。

4. 小結(jié)

本節(jié)討論了通過 HTTP + SSL 的方式,規(guī)避 HTTP 協(xié)議在安全上的不足。HTTP 協(xié)議存在安全隱患,容易遭到惡意攻擊,例如中間人攻擊;HTTP 安全時(shí)傳輸層安全的范疇,可以通過重定向 HTTP 連接和強(qiáng)制安全傳輸?shù)姆绞皆黾悠浒踩裕籗pring Security 支持通過配置將 HTTP 請求轉(zhuǎn)換為 HTTPS 請求;Spring Security 支持為 B/S 應(yīng)用強(qiáng)制使用安全傳輸。下節(jié)我們討論如果通過 Spring Security 統(tǒng)一不同 Web 容器間的訪問控制差異。

3. log 階段

log 階段是 http 請求 11 個(gè)階段中的最后一個(gè)階段,這個(gè)階段主要的任務(wù)就是記錄請求的訪問日志。這個(gè)階段主要涉及的是 ngx_http_log_module 這個(gè)模塊。該模塊提供了幾個(gè)常用指令,如 access_log 和 log_format 指令,分別定義了請求日志的記錄文件以及記錄的日志格式。# 官方例子log_format compression '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" "$gzip_ratio"';access_log /spool/logs/nginx-access.log compression buffer=32k;# access_log指令用法Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];access_log off;Default: access_log logs/access.log combined;Context: http, server, location, if in location, limit_except# log_format指令用法Syntax: log_format name [escape=default|json|none] string ...;Default: log_format combined "...";Context: http# 是否打開日志緩存Syntax: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];open_log_file_cache off;Default: open_log_file_cache off;Context: http, server, location

3.4 HSTS 頭

HTTP Strict Transport Security(HSTS)頭,在 Spring Security 中是被默認(rèn)開啟的,我們可以修改它的默認(rèn)狀態(tài),如下:@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .headers(headers -> headers .httpStrictTransportSecurity(hsts -> hsts .includeSubDomains(true) .preload(true) .maxAgeInSeconds(31536000) ) ); }}

1. 前言

上節(jié)我們討論了 HTTP 請求中,如何通過配置其頭部參數(shù)達(dá)到安全性提升的效果,本節(jié)將討論 HTTP 協(xié)議層面的安全性提升方法。HTTP 通訊協(xié)議是一種明文傳輸協(xié)議,存在安全隱患,所以通常我們會使用 TLS 方式保障其安全。本節(jié)我們主要討論 Spring Security 中的 HTTP 安全。

直播
查看課程詳情
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號