一、前言
有時候,web平臺上線后,需要屏蔽某個服務接口,但又不想重新上線,可以采用nginx屏蔽指定平臺接口的辦法。
二、具體操作
在nginx的配置文件nginx.conf文件的server節點中,添加一個location,示例如下:
1
2
3
|
location /your url { return 403; } |
這里具體以nginx自帶nginx.conf為例,屏蔽根URL路徑/:
屏蔽前
1
2
3
4
|
location / { root html; index index.html index.htm; } |
訪問nginx index.html頁面結果如下:
屏蔽后
1
2
3
4
5
|
location / { return 403; root html; index index.html index.htm; } |
訪問nginx index.html頁面結果如下:
修改完nginx.conf配置文件后,不用重啟nginx,執行命令nginx -s reload重新加載配置文件,修改的規則即可生效。
補充知識:nginx屏蔽特定http_referer的請求
在nginx.conf的server配置項中加入
1
2
3
|
if ($http_referer ~* "www.xxx.com" ) { return 403; } |
以上這篇nginx屏蔽指定接口(URL)的操作方式就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/tterminator/article/details/70186033