Question
PHP-FPM Error on NGINX (502 Bad Gateway)
I am getting the following error on error log for my LEMP Ubuntu 20.04 setup on NGINX
704#704: *58 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx server: domain.tld, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "domain.tld"
My domain configuration is as follows listed under /etc/nginx/conf.d/domain.conf
server_name domain.tld;
root /var/www/domain/;
index index.html index.php;
access_log /sites/domain/logs/access.log;
error_log /sites/domain/logs/error.log;
# Don't allow pages to be rendered in an iframe on external domains.
add_header X-Frame-Options "SAMEORIGIN";
# MIME sniffing prevention
add_header X-Content-Type-Options "nosniff";
# Enable cross-site scripting filter in supported browsers.
add_header X-Xss-Protection "1; mode=block";
# Prevent access to hidden files
location ~* /\.(?!well-known\/) {
deny all;
}
# Prevent access to certain file extensions
location ~\.(ini|log|conf)$ {
deny all;
}
# Enable WordPress Permananent Links
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
configuration under /etc/nginx/sites-available/ is attached
server {
listen 80;
listen [::]:80;
root /var/www/csgg;
index i index.php index.html index.htm;
#server_name csgg.in;
client_max_body_size 100M;
autoindex off;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Can someone shed some light on how to get PHP-FPM to start behaving normally? I am able to access .txt and .HTML files in the root folder.
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.
×