title: 502 Bad Gateway nginx/1.10.0 (Ubuntu)
body: <p>Can anybody help me with my nginx configuration, it's driving me nuts.</p>
  
  <p>I've made so many changes to my sites-available and sites-enabled and my nginx.conf file that i'm not sure what's up or down anymore. I change from 404 errors to 502 errors. I've changed permissions on folders and changed ports that it listens to. </p>
  
  <pre><code>    server {
      listen      80;
  
      server_name www.mysite.com mysite.com;
      keepalive_timeout   70;
      root        /var/www/html;
      index index.html index.php;
  
      access_log /var/log/nginx/access_log;
      error_log /var/log/nginx/error_log;
  
      location / {
          try_files $uri $uri/ @handler;
          expires 30d;
      }
      #location /app/                       { deny all; }
      #location /includes/                  { deny all; }
      #location /lib/                       { deny all; }
      #location /media/downloadable/        { deny all; }
      #location /pkginfo/                   { deny all; }
      #location /report/config.xml          { deny all; }
      #location /var/                       { deny all; }
  
      location /var/export/ {
          auth_basic              "Restricted";
          auth_basic_user_file    htpasswd;
          autoindex               on;
      }
      location  /. {
          return 404;
      }
  
      location @handler {
          rewrite / /index.php;
      }
  
      location ~ .php/ {
          rewrite ^(.*.php)/ $1 last;
      }
  
      location ~ \.php$ {
          try_files $uri =404;
          expires off;
          fastcgi_read_timeout 900s;
          fastcgi_index index.php;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include /etc/nginx/fastcgi_params;
      }
  rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&amp;d=$1 last;
      rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&amp;d=$1 last;
  
      location /lib/minify/ {
          allow all;
      }
      gzip on;
      #gzip_comp_level 9;
      gzip_min_length  1000;
      gzip_proxied any;
      gzip_types       text/plain application/xml text/css text/js application/x-javascript;
  }
  </code></pre>
  
  <p>nginx.conf</p>
  
  <pre><code>    user www-data;
  worker_processes auto;
  pid /run/nginx.pid;
  
  events {
      worker_connections 768;
      # multi_accept on;
  }
  
  http {
  
      ##
      # Basic Settings
      ##
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      # server_tokens off;
  
       server_names_hash_bucket_size 64;
      # server_name_in_redirect off;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      ##
      # SSL Settings
      ##
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
      ssl_prefer_server_ciphers on;
  
      ##
      # Logging Settings
      ##
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      ##
      # Gzip Settings
      ##
  
      gzip on;
      gzip_disable "msie6";
  
      # gzip_vary on;
      # gzip_proxied any;
      # gzip_comp_level 6;
      # gzip_buffers 16 8k;
      # gzip_http_version 1.1;
      # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  
      ##
      # Virtual Host Configs
      ##
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  
  
  #mail {
  #   # See sample authentication script at:
  #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  # 
  #   # auth_http localhost/auth.php;
  #   # pop3_capabilities "TOP" "USER";
  #   # imap_capabilities "IMAP4rev1" "UIDPLUS";
  # 
  #   server {
  #       listen     localhost:110;
  #       protocol   pop3;
  #       proxy      on;
  #   }
  # 
  #   server {
  #       listen     localhost:143;
  #       protocol   imap;
  #       proxy      on;
  #   }
  #}
  </code></pre>
  
  <p>If i tail -f my access log:</p>
  
  <pre><code>52.25.122.161 - - [12/Feb/2017:00:20:36 -0700] "GET / HTTP/1.1" 502 182 "-" "Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0"
  66.249.64.68 - - [12/Feb/2017:00:36:15 -0700] "GET /robots.txt HTTP/1.1" 502 182 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  66.249.64.68 - - [12/Feb/2017:01:47:53 -0700] "GET /robots.txt HTTP/1.1" 502 182 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  27.105.104.2 - - [12/Feb/2017:02:55:17 -0700] "GET / HTTP/1.0" 502 182 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  139.162.108.53 - - [12/Feb/2017:06:03:19 -0700] "GET / HTTP/1.1" 502 584 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
  86.111.145.222 - - [12/Feb/2017:06:46:19 -0700] "GET / HTTP/1.1" 502 182 "-" "curl/7.17.1 (mips-unknown-linux-gnu) libcurl/7.17.1 OpenSSL/0.9.8i zlib/1.2.3"
  89.248.163.3 - - [12/Feb/2017:07:53:05 -0700] "GET /muieblackcat HTTP/1.1" 502 182 "-" "-"
  89.248.163.3 - - [12/Feb/2017:07:53:05 -0700] "GET //pma/scripts/setup.php HTTP/1.1" 404 178 "-" "-"
  89.248.163.3 - - [12/Feb/2017:07:53:05 -0700] "GET //phpmyadmin/scripts/setup.php HTTP/1.1" 404 178 "-" "-"
  54.169.31.205 - - [12/Feb/2017:08:47:01 -0700] "GET / HTTP/1.1" 502 182 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB6 (.NET CLR 3.5.30729)"
  </code></pre>