nginx禁止外网访问登录页面,SQL 注入、XSS 攻击配置

简介: nginx禁止外网访问登录页面,SQL 注入、XSS 攻击配置

nginx windows 注册服务 下载,关注公众号lovepythoncn,回复nginx

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
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;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
  upstream 192.168.30.246 {
    server 127.0.0.1:8080;
  }
    server {
        listen       80;
        server_name  127.0.0.1;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
           # root   html;
           # index  index.html index.htm;
      proxy_set_header Host $host;
      proxy_set_header  X-Real-IP        $remote_addr;
      proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://192.168.30.246/;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    location  ^~ /login.jsp {
      deny all;
    }
    location  ^~ /j_spring_security_check {
      deny all;
    }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    if ($request_method !~* GET|POST) { return 444; }
      #使用444错误代码可以更加减轻服务器负载压力。
      #防止SQL注入
      if ($query_string ~* (\$|'|--|[+|(%20)]union[+|(%20)]|[+|(%20)]insert[+|(%20)]|[+|(%20)]drop[+|(%20)]|[+|(%20)]truncate[+|(%20)]|[+|(%20)]update[+|(%20)]|[+|(%20)]from[+|(%20)]|[+|(%20)]grant[+|(%20)]|[+|(%20)]exec[+|(%20)]|[+|(%20)]where[+|(%20)]|[+|(%20)]select[+|(%20)]|[+|(%20)]and[+|(%20)]|[+|(%20)]or[+|(%20)]|[+|(%20)]count[+|(%20)]|[+|(%20)]exec[+|(%20)]|[+|(%20)]chr[+|(%20)]|[+|(%20)]mid[+|(%20)]|[+|(%20)]like[+|(%20)]|[+|(%20)]iframe[+|(%20)]|[\<|%3c]script[\>|%3e]|javascript|alert|webscan|dbappsecurity|style|confirm\(|innerhtml|innertext)(.*)$) { return 555; }
       if ($uri ~* (/~).*) { return 501; }
       if ($uri ~* (\\x.)) { return 501; }
      #防止SQL注入 
       if ($query_string ~* "[;'<>].*") { return 509; }
       if ($request_uri ~ " ") { return 509; }
       if ($request_uri ~ (\/\.+)) { return 509; }
       if ($request_uri ~ (\.+\/)) { return 509; }
       #if ($uri ~* (insert|select|delete|update|count|master|truncate|declare|exec|\*|\')(.*)$ ) { return 503; }
      #防止SQL注入
       if ($request_uri ~* "(cost\()|(concat\()") { return 504; }
       if ($request_uri ~* "[+|(%20)]union[+|(%20)]") { return 504; }
       if ($request_uri ~* "[+|(%20)]and[+|(%20)]") { return 504; }
       if ($request_uri ~* "[+|(%20)]select[+|(%20)]") { return 504; }
       if ($request_uri ~* "[+|(%20)]or[+|(%20)]") { return 504; }
       if ($request_uri ~* "[+|(%20)]delete[+|(%20)]") { return 504; }
       if ($request_uri ~* "[+|(%20)]update[+|(%20)]") { return 504; }
       if ($request_uri ~* "[+|(%20)]insert[+|(%20)]") { return 504; }
       if ($query_string ~ "(<|%3C).*script.*(>|%3E)") { return 505; }
       if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") { return 505; }
       if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") { return 505; }
       if ($query_string ~ "proc/self/environ") { return 505; }
       if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") { return 505; }
       if ($query_string ~ "base64_(en|de)code\(.*\)") { return 505; }
       if ($query_string ~ "[a-zA-Z0-9_]=http://") { return 506; }
       if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") { return 506; }
       if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") { return 506; }
       if ($query_string ~ "b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)b") { return 507; }
       if ($query_string ~ "b(erections|hoodia|huronriveracres|impotence|levitra|libido)b") {return 507; }
       if ($query_string ~ "b(ambien|bluespill|cialis|cocaine|ejaculation|erectile)b") { return 507; }
       if ($query_string ~ "b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)b") { return 507; }
      #这里大家根据自己情况添加删减上述判断参数,cURL、wget这类的屏蔽有点儿极端了,但要“宁可错杀一千,不可放过一个”。
       if ($http_user_agent ~* YisouSpider|ApacheBench|WebBench|Jmeter|JoeDog|Havij|GetRight|TurnitinBot|GrabNet|masscan|mail2000|github|wget|curl|Java|python) { return 508; }
      #同上,大家根据自己站点实际情况来添加删减下面的屏蔽拦截参数。
       if ($http_user_agent ~* "Go-Ahead-Got-It") { return 508; }
       if ($http_user_agent ~* "GetWeb!") { return 508; }
       if ($http_user_agent ~* "Go!Zilla") { return 508; }
       if ($http_user_agent ~* "Download Demon") { return 508; }
       if ($http_user_agent ~* "Indy Library") { return 508; }
       if ($http_user_agent ~* "libwww-perl") { return 508; }
       if ($http_user_agent ~* "Nmap Scripting Engine") { return 508; }
       if ($http_user_agent ~* "~17ce.com") { return 508; }
       if ($http_user_agent ~* "WebBench*") { return 508; }
       if ($http_user_agent ~* "spider") { return 508; } #这个会影响国内某些搜索引擎爬虫,比如:搜狗
      #拦截各恶意请求的UA,可以通过分析站点日志文件或者waf日志作为参考配置。
       if ($http_referer ~* 17ce.com) { return 509; }
      #拦截17ce.com站点测速节点的请求,所以明月一直都说这些测速网站的数据仅供参考不能当真的。
       if ($http_referer ~* WebBench*") { return 509; }
      #拦截WebBench或者类似压力测试工具,其他工具只需要更换名称即可。
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
相关文章
|
19天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
24 0
|
17天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
78 0
|
2天前
|
SQL 安全 Go
如何在 Python 中进行 Web 应用程序的安全性管理,例如防止 SQL 注入?
在Python Web开发中,确保应用安全至关重要,主要防范SQL注入、XSS和CSRF攻击。措施包括:使用参数化查询或ORM防止SQL注入;过滤与转义用户输入抵御XSS;添加CSRF令牌抵挡CSRF;启用HTTPS保障数据传输安全;实现强身份验证和授权系统;智能处理错误信息;定期更新及审计以修复漏洞;严格输入验证;并培训开发者提升安全意识。持续关注和改进是保证安全的关键。
9 0
|
8天前
|
存储 安全 应用服务中间件
解密Nginx限流机制:有效应对DDoS攻击与高并发流量
解密Nginx限流机制:有效应对DDoS攻击与高并发流量
21 0
|
9天前
|
SQL 安全 PHP
CTF--Web安全--SQL注入之Post-Union注入
CTF--Web安全--SQL注入之Post-Union注入
|
11天前
|
应用服务中间件 nginx
nginx进行反向代理的配置
在Nginx中设置反向代理的步骤:编辑`/etc/nginx/nginx.conf`,在http段加入配置,创建一个监听80端口、服务器名为example.com的虚拟主机。通过`location /`将请求代理到本地3000端口,并设置代理头。保存配置后,使用`sudo nginx -s reload`重载服务。完成配置,通过example.com访问代理服务器。
18 0
|
12天前
|
应用服务中间件 网络安全 nginx
nginx配置https访问
nginx配置https访问
25 0
|
21天前
|
应用服务中间件 nginx
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
9 0
|
22天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
18 0
|
22天前
|
应用服务中间件 nginx
nginx配置https和直接访问静态文件的方式
nginx配置https和直接访问静态文件的方式
27 3