Fresh wordpress install results in 502 bad gateway nginx


#1

Hi there,

Somehow I can’t get a fresh Wordpress installation by running ee site create mysite.com --wp It results in a 502 Bad Gateway Nginx.

I don’t know what is going wrong. If I delete mysite.com and try to create it again it still gives me this 502 error.

Where should I look at when this happens?

Thanks in advance!


#2

Please check if your PHP is running.

Try restarting PHP services.


#3

Hi Prabuddha,

Thanks a lot for your reply. I’m a real noob with this;-) I have restarted the services but didn’t work.

I did checked some php info with ee info --php.

I noticed that the parameter “user” is empty. While the docs says it should be “www-data”.

Should I change this? And if yes, how would I do that?

Cheers


#4

Empty ‘user’ parameter doesn’t matter.

Run ee stack status to make sure your php-fpm service is running or could also run ps aux | grep php to see a running php process. Are you using unix socket or tcp?

Pardon the obvious question but did you setup your DNS records to point to this new domain by server IP?

Did you recently do any upgrade to ee? which version do you run? what is the output of ee --v ?

B/c if you had php5-fpm before and you upgraded to newest Nginx it could have changed to php56 or php7 and you need to reconfigure your Ngnix location ~ \.php$ block.


#5

Hi Tyrro,

Thanks for your reply.

I checked the status. See my image for the output.

I’m not sure about the Unix socket or tcp. How do I check it. Ee is running on Digital Ocean. Does that make sense?

The DNS is pointing to my server (Digital Ocean).

The version of ee is the latest version. (v3.5.5)

As you can see, I have multiple php versions running. In what file can I reconfigure the Nginx? And should I check?

As you can see, i’m a real noob with this :wink: But with this help I come pretty far.

Cheers!


#6

I have 502 error after upgraded to php56.

Tyrro, could you, please, specify how can I reconfigure Ngnix location ~ .php$ block?


#7

Please run sudo ee site edit mysite.com this will open your nginx config file for mysite.com. Paste the config here.


#8
server {
  server_name z-muz.ru www.z-muz.ru;

  access_log /var/log/nginx/z-muz.ru.access.log rt_cache;
  error_log /var/log/nginx/z-muz.ru.error.log;

  root /var/www/z-muz.ru/current;

  index index.php index.html index.htm;

  include common/php.conf;
  include common/wpcommon.conf;
  include common/locations.conf;
  include anonima/basia.conf;
  include /var/www/z-muz.ru/conf/nginx/*.conf;
}

common/php.conf:

# PHP NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee)
location / {
  try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
  try_files $uri =404;
  include fastcgi_params;
  fastcgi_pass php;
}

common/wpcommon.conf:

# WordPress COMMON SETTINGS
# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee)
# Limit access to avoid brute force attack
location = /wp-login.php {
  limit_req zone=one burst=1 nodelay;
  include fastcgi_params;
  fastcgi_pass php;
}
# Disable wp-config.txt
location = /wp-config.txt {
  deny all;
  access_log off;
  log_not_found off;
}
# Disallow php in upload folder
location /wp-content/uploads/ {
  location ~ \.php$ {
    #Prevent Direct Access Of PHP Files From Web Browsers
    deny all;
  }
}
# Yoast sitemap
location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
  rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
  rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
  # Rules for yoast sitemap with wp|wpsubdir|wpsubdomain
  rewrite ^.*/sitemap_index\.xml$ /index.php?sitemap=1 last;
  rewrite ^.*/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
  # Following lines are options. Needed for WordPress seo addons
  rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;
  rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
  rewrite ^/geo_sitemap\.xml$ /index.php?sitemap=wpseo_local last;
  rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;
  access_log off;
}

common/locations.conf:

# NGINX CONFIGURATION FOR COMMON LOCATION
# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee)
# Basic locations files
location = /favicon.ico {
  access_log off;
  log_not_found off;
  expires max;
}
location = /robots.txt {
  # Some WordPress plugin gererate robots.txt file
  # Refer #340 issue
  try_files $uri $uri/ /index.php?$args;
  access_log off;
  log_not_found off;
}
# Cache static files
location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf)$ {
  add_header "Access-Control-Allow-Origin" "*";
  access_log off;
  log_not_found off;
  expires max;
}
# Security settings for better privacy
# Deny hidden files
location ~ /\.well-known {
  allow all;
}
location ~ /\. {
  deny all;
  access_log off;
  log_not_found off;
}
# Deny backup extensions & log files
location ~* ^.+\.(bak|log|old|orig|original|php#|php~|php_bak|save|swo|swp|sql)$ {
  deny all;
  access_log off;
  log_not_found off;
}
# Return 403 forbidden for readme.(txt|html) or license.(txt|html) or example.(txt|html)
if ($uri ~* "^.+(readme|license|example)\.(txt|html)$") {
  return 403;
}
# Status pages
location /nginx_status {
  stub_status on;
  access_log off;
  include common/acl.conf;
}
location ~ ^/(status|ping) {
  include fastcgi_params;
  fastcgi_pass php;
  include common/acl.conf;
}
# EasyEngine (ee) utilities
# phpMyAdmin settings
location /pma {
  return 301 https://$host:22222/db/pma;
}
location /phpMyAdmin {
  return 301 https://$host:22222/db/pma;
}
location /phpmyadmin {
  return 301 https://$host:22222/db/pma;
}
# Adminer settings
location /adminer {
  return 301 https://$host:22222/db/adminer;
}

anonima/basia.conf:

# Remove `/assets/themes/theme_name` from assets URL
rewrite ^/view/(.*) /assets/themes/basia/$1 break;

#9

I checked my own setting and they are exactly like yours and it’s working fine. The only difference is on your server block you have this include

include anonima/basia.conf;

can you try to comment this with # like so:

#include anonima/basia.conf; and see if it makes a difference.


#10

Visit your website until it shows 502 bad gateway nginx then go to /var/log/nginx then open your domain.com.error.log file paste it here


#11

Hello,

I am having the same exact issue on a fresh server on my first WordPress install using EasyEngine. I have tried all the things previously said in this thread. My config files look exactly the same as the OP except I do not have the line that says “include anonima/basia.conf;”

Here it is:

2016/05/09 17:40:39 [error] 21954#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 173.245.56.126, server: example.com, request: “GET / HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “example.com

[Note: I replaced all the places where my domain was with “example.com” (without quotes)]

There are about 20 more lines of that exact same error.

Any ideas why this might be happening?


#12

it was an error in creating run/php , which prevented php from starting. run apt-get upgrade and then restart your web stack (ee stack restart), it should be fixed.


#13

@LQDForce you are my hero. I was having this exact same issue and I had been chasing down a red herring that it was my iptables. You have totally made my day.

This fixed everything


#14

Just got some time to try to fix the issue. Thanks LQDForce. You’re the hero of the day. You’ve made it happen! Finally I can work again :wink:

Cheers.


#15