【问题标题】:Cloudflare Error 502 Bad Gateway - Nginx - Laravel5Cloudflare 错误 502 错误网关 - Nginx - Laravel5
【发布时间】:2020-02-13 18:41:05
【问题描述】:

最近,当我在仪表板中登录我的网站时,我不断看到这个屏幕

如何防止这种情况发生?

我在 Nginx 上使用 CloudFlare。

我曾经使用过 Fail2Ban,但我禁用了它。

[nginx-req-limit]

enabled   = false
filter    = nginx-req-limit
action    = iptables-multiport[name=ReqLimit, port="http,https", protocol=tcp]
        jdoeddos
logpath   = /var/log/nginx/default-error.log
findtime  = 10
bantime   = 7200
maxretry  = 20

Nginx

#limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;

server {
    listen 80 default_server;
    server_name jdoe.com www.jdoe.com;
    root /home/forge/jdoe/public;



    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    index index.html index.htm index.php;

    charset utf-8;

    
    

    location / {
        #limit_req zone=one burst=2 nodelay;
        try_files $uri $uri/ /index.php?$query_string;
        add_header 'Access-Control-Allow-Origin' '*';
    }

    location ~ \.php$ {
        #limit_req zone=one burst=2 nodelay;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

  

    access_log off;
    error_log  /var/log/nginx/default-error.log error;

    error_page 404 /index.php;



    location ~ /\.ht {
        deny all;
    }

}

有什么需要关闭的设置吗?

【问题讨论】:

  • 您是否尝试过其他 IP 并重新启动网络服务器?也发布你的 nginx 配置
  • 我记得在主要路线有效而其余路线无效的情况下遇到了这个问题。此问题与您的公用文件夹中的 .htaccess 文件有关。最简单的解决方案是创建一个新的 laravel 项目,采用该项目 .htaccess 并根据您的要求进行自定义。如果您需要进行任何更改,否则只需替换文件。 :) 保留备份,以防万一出现问题

标签: laravel nginx laravel-5 cloudflare fail2ban


【解决方案1】:

改变这个

location ~ \.php$ {
        #limit_req zone=one burst=2 nodelay;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }

【讨论】:

  • 您添加的 2 行是什么意思?能解释一下吗?
  • 第 2 行,没有找到页面,但此行适用于你 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params;
猜你喜欢
  • 2012-09-25
  • 1970-01-01
  • 2011-05-14
  • 2019-06-05
  • 2015-08-10
  • 2021-11-19
  • 2014-12-07
  • 2020-09-29
  • 2012-07-16
相关资源
最近更新 更多