Question

Nginx bad gateway error with cloudflare

Posted October 16, 2021 381 views
NginxWordPress

I have setup argo tunnel on nginx and it’s gives 502 error, but but when it’s dns setup the web server work’s great!!.

tunnel: 796c6fde-bae0-476f-86d6-3dfd022d6143
credentials-file: /home/cloudcreatr/.cloudflared/796c6fde-bae0-476f-86d6-3dfd022d6143.json

ingress:
  - hostname: wp.cloudcreatr.com
    service: https://localhost:443
    originRequest:
      connectTimeout: 10s
      noTLSVerify: true
  # Catch-all rule, which just responds with 404 if traffic doesn't match any of
  # the earlier rules
  - service: http_status:404
warp-routing:
  enabled: true

Nginx site config

server {

    server_name wp.cloudcreatr.com;
    root /var/www/wp;

    index index.html index.htm index.php;

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl_certificate         /etc/ssl/cert.pem;
    ssl_certificate_key     /etc/ssl/key.pem;

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }

    location / {
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

}

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hello there,

I found the below article which covers most of the cases and will help you in troubleshooting this issue. Please follow the link below and let us know if that helps:

https://github.com/cloudflare/cloudflared/issues/270

https://community.cloudflare.com/t/cloudflare-argo-tunnel-gives-bad-gateway-error/316404/3

I hope this helps! Let me know if you have further questions!

Hi @omnaidu,

Usually, when you get a 502 error, it’s related to either your Nginx configuration file or your App’s config file. Looking at the Ngxin config file, all looks alright.

What I’ll recommend you to do is, troubleshoot the App, look at the logs, what do they give as an error? Additionally, check Nginx logs, they should be in /var/log/nginx/error_log. See the exact error, it should help you fix the one you are getting.

As a last resort, you can always turn off Cloudflare and troubleshoot your Application until it works. Then turn on Cloudflare again.