鍍金池/ 問答/Linux  網(wǎng)絡(luò)安全/ NGINX屏蔽ip,https(443端口)有效,而http(80端口)無效

NGINX屏蔽ip,https(443端口)有效,而http(80端口)無效

自己設(shè)置的ipblock.conf文件,deny了自己的手機(jī)ip
然后include ipblock.conf;到服務(wù)器的nginx.conf的http{}下面
效果:

  • 網(wǎng)站1是https協(xié)議,ip屏蔽成功
  • 網(wǎng)站2是http協(xié)議,ip屏蔽無效

然后將在http網(wǎng)站的conf文件里面添加了include ipblock.conf;依然無效
然后將deny ip;直接寫到http協(xié)議網(wǎng)站的conf文件里面,還是無法屏蔽

請(qǐng)教各位上仙,這個(gè)怎么解決

相關(guān)配置:
文件夾/conf/下面
文件:ipblock.conf

deny ip;
…………

文件:nginx.conf

http
    {

        include       mime.types;
        default_type  application/octet-stream;
        include ipblock.conf;
        …………

文件夾/conf/vhost下面
網(wǎng)站1(https協(xié)議).conf

server
    {
        listen 80;
        #listen [::]:80;
        server_name www.name1.com name1.com *.name1.com;
        return 301 https://www.nam1e.com$request_uri;
    }

server
    {
        listen 443 ssl http2;
        #listen [::]:443 ssl http2;
        server_name www.name1.com name1.com *.name1.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.name1.com;
        ssl on;
        …………

網(wǎng)站2(http協(xié)議).conf

server
    {
        listen 80;
        #listen [::]:80;
        server_name www.name2.com name2.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.name2.com;
        
        //這兒添加的include ipblock.conf;
        //或者直接寫的deny ip;


回答
編輯回答
喵小咪

可能的原因:

  1. 你的手機(jī)流量被運(yùn)營(yíng)商做了緩存
  2. 你的手機(jī)的瀏覽器開啟了類似的“省流量”的功能,比如Chrome和UC都有這種功能
  3. 運(yùn)營(yíng)商對(duì)于不同協(xié)議,走的出口不一樣

簡(jiǎn)而言之,盡量不要用手機(jī)來做這種涉及到IP的測(cè)試,除非你確定中間經(jīng)過什么


可以增加兩項(xiàng)配置來做測(cè)試:

location = /ip {
    default_type text/plain;
    allow all;
    return 200 "$remote_addr, $realip_remote_addr, $http_x_real_ip";
}
location = /deny {
    deny all;
}
  1. 然后用手機(jī)訪問 /ip,看下你服務(wù)器獲取到的IP是多少;
  2. 用手機(jī)訪問 /deny,看屏蔽是否有效。
2017年8月9日 01:38
編輯回答
撥弦

看起來配置沒有問題。

若是在 ipblock.conf 文件中使用了靜態(tài) IP,例如

deny 1.2.3.4;
allow all;

那很可能是你的手機(jī)瀏覽器訪問 http 時(shí)使用了某些加速服務(wù),它透過第三方服務(wù) IP 去訪問你的網(wǎng)站。
但由于 https 是加密連接,無法加速,因此使用的是你的手機(jī) IP。

你可以通過查詢 nginx 訪問日志,或在服務(wù)器抓包來確認(rèn)。

2017年8月11日 15:57