Nginx 運維之域名驗證的方法示例
各公眾平臺在配置接口域名時會驗證開發(fā)者對域名的配置權(quán), 生成隨機的文本及字符串,讓放置在域名根目錄可以通過域名直接訪問到即通過驗證。
示例為驗證域名 abc.com 可以通過根路由訪問 6CysNYj8Hb.txt 響應(yīng)體為字符串 01df2ddab4774ba2676a5563ccb79ffa。
$ curl https://abc.com/6CysNYj8Hb.txt 01df2ddab4774ba2676a5563ccb79ffa
方案一
配置有 root 的 server,直接把隨機文檔放置在該目錄下即可,不需要重啟 nginx 服務(wù)。
方案二
匹配路由,指定隨機文檔所在目錄, 需要重啟 nginx。
location ~* 6CysNYj8Hb\.txt { root /data/ftp; }
方案三(推薦)
匹配路由,直接返回需要驗證的隨機字符串,需要重啟 nginx。
location = /6CysNYj8Hb.txt { default_type text/html; return 200 '01df2ddab4774ba2676a5563ccb79ffa'; }
參考
補充:Nginx域名重定向
1、更改配置文件test.com.conf
[root@jimmylinux-001 vhost]# vim test.com.conf server { listen 80; server_name test.com test2.com test3.com; index index.html index.htm index.php; root /data/wwwroot/test.com; if ($host != 'test.com' ) { rewrite ^/(.*)$ http://test.com/$1 permanent; } }
2、curl測試
[root@jimmylinux-001 vhost]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@jimmylinux-001 vhost]# /usr/local/nginx/sbin/nginx -s reload [root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test2.com/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Thu, 07 Jun 2018 16:47:36 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://test.com/index.html [root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test2.com/admin/index.html -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Thu, 07 Jun 2018 16:48:08 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://test.com/admin/index.html [root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test3.com/admin/index.html/adjlfj -I HTTP/1.1 301 Moved Permanently Server: nginx/1.12.1 Date: Thu, 07 Jun 2018 16:48:35 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://test.com/admin/index.html/adjlfj [root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test4.com/admin/index.html/adjlfj -I HTTP/1.1 404 Not Found Server: nginx/1.12.1 Date: Thu, 07 Jun 2018 16:48:43 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在Linux和Windows系統(tǒng)上安裝Nginx服務(wù)器的教程
這篇文章主要介紹了在Linux和Windows系統(tǒng)上安裝Nginx服務(wù)器的教程,Linux系統(tǒng)這里以CentOS為代表,需要的朋友可以參考下2015-08-08Nginx HttpMemcModule和直接訪問memcached效率對比測試
2013-09-09Nginx如何根據(jù)前綴路徑轉(zhuǎn)發(fā)到不同的Flask服務(wù)
這篇文章主要介紹了Nginx如何根據(jù)前綴路徑轉(zhuǎn)發(fā)到不同的Flask服務(wù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01Nginx?map?實現(xiàn)時間格式轉(zhuǎn)換的方法
最近我們需要把?Nginx?的日志接入到自研的日志采集平臺上,但是這個平臺只支持?JSON?格式,所以需要把?Nginx?日志格式改成?JSON?格式,這篇文章主要介紹了Nginx?map?實現(xiàn)時間格式轉(zhuǎn)換,需要的朋友可以參考下2023-09-09nginx訪問動態(tài)接口報錯404Not Found問題解決
本文主要介紹了nginx訪問動態(tài)接口報錯404Not Found問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03nginx?status配置及參數(shù)配置小結(jié)
本文主要介紹了nginx?status配置及參數(shù)配置,其實要監(jiān)控Nginx的狀態(tài)非常簡單,它內(nèi)建了一個狀態(tài)頁,只需修改Nginx配置啟用Status即可,感興趣的可以了解一下2024-04-04