Nginx bad gateway error with cloudflare

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

  - hostname:
    service: https://localhost:443
      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
  enabled: true

Nginx site config

server {
    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;


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

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.

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:

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