Nginx on Compute Engine return 502 Bad Gateway

2019-08-23 12:51发布

问题:

I'm trying to set up a WordPress site in Compute Engine with Nginx and Cloud SQL. I have setup an instance with Ubuntu 18.0 and install the Nginx and WordPress by using the following commands:

  1. $ sudo apt update
  2. $ sudo apt install nginx
  3. sudo apt-get install php-fpm php-mysql
  4. sudo nano /etc/php/7.2/fpm/php.ini
  5. and change cgi.fix_pathinfo=0 in php.ini
  6. sudo systemctl restart php7.2-fpm
  7. sudo nano /etc/nginx/sites-available/default

and setup like this:

server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;

server_name COMPUTE_ENGINE_INSTANCE_STATIC_IP;

location / {
    try_files $uri $uri/ =404;
}

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

location ~ /\.ht {
    deny all;
    }
}
  1. sudo nginx -t and it returns success message.
  2. sudo systemctl reload nginx
  3. sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
  4. sudo systemctl restart php7.2-fpm
  5. cd /tmp
  6. curl -O https://wordpress.org/latest.tar.gz
  7. tar xzvf latest.tar.gz
  8. cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
  9. mkdir /tmp/wordpress/wp-content/upgrade
  10. sudo cp -a /tmp/wordpress/. /var/www/html
  11. sudo adduser root www-data
  12. sudo chown -R kimseasok:www-data /var/www/html
  13. sudo chmod -R g+rwX /var/www/html

Now, when I try to access my instance IP it returns this error:

502 Bad Gateway

nginx/1.14.0 (Ubuntu)

What's wrong here?

Help me, please!

Thanks in advance!