Failed to implement Nginx caching - connection refused
up vote
2
down vote
favorite
I'm having trouble getting my site to work after trying to implement Nginx caching.
I use Ubuntu 16.04 (xenial), Nginx (1.10.3), PHP-FPM (7.0) and WordPress.
Port 9000 (for php-fpm) is unfiltered by UFW.
Reproducing my environment
1 - setting confs:
nginx.conf
default conf
virtual host
/etc/php/7.0/fpm/pool.d/www.conf (comments omitted)
2 - Creating a cache dir:
mkdir -p /var/cache/nginx/fastcgi_temp/cache/
chmod 755 /var/cache/nginx/fastcgi_temp/cache/
chown www-data:www-data /var/cache/nginx/fastcgi_temp/cache/
3 - Server restart:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
4- Error and debug tries:
*1 connect() failed (111: Connection refused) while connecting to upstream,
client: MY_IP_ADDRESS, server: example.com, request: "GET /
HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000".
The browser gives:
502 Bad Gateway nginx/1.10.3 (Ubuntu)
Debug:
/etc/init.d/php*-fpm status
brings:
â php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-27 07:09:28 UTC; 3s ago
Process: 16336 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 16346 (php-fpm7.0)
Status: "Ready to handle connections"
My question
Why is the connection refused and my site is down?
Update for NerdOfLinux:
+ curl -I example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
And
grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
+ grep --color=auto -v ';'
+ grep --color=auto listen /etc/php/7.0/fpm/pool.d/www.conf
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
16.04 server php nginx cache
add a comment |Â
up vote
2
down vote
favorite
I'm having trouble getting my site to work after trying to implement Nginx caching.
I use Ubuntu 16.04 (xenial), Nginx (1.10.3), PHP-FPM (7.0) and WordPress.
Port 9000 (for php-fpm) is unfiltered by UFW.
Reproducing my environment
1 - setting confs:
nginx.conf
default conf
virtual host
/etc/php/7.0/fpm/pool.d/www.conf (comments omitted)
2 - Creating a cache dir:
mkdir -p /var/cache/nginx/fastcgi_temp/cache/
chmod 755 /var/cache/nginx/fastcgi_temp/cache/
chown www-data:www-data /var/cache/nginx/fastcgi_temp/cache/
3 - Server restart:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
4- Error and debug tries:
*1 connect() failed (111: Connection refused) while connecting to upstream,
client: MY_IP_ADDRESS, server: example.com, request: "GET /
HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000".
The browser gives:
502 Bad Gateway nginx/1.10.3 (Ubuntu)
Debug:
/etc/init.d/php*-fpm status
brings:
â php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-27 07:09:28 UTC; 3s ago
Process: 16336 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 16346 (php-fpm7.0)
Status: "Ready to handle connections"
My question
Why is the connection refused and my site is down?
Update for NerdOfLinux:
+ curl -I example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
And
grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
+ grep --color=auto -v ';'
+ grep --color=auto listen /etc/php/7.0/fpm/pool.d/www.conf
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
16.04 server php nginx cache
Can we get the output ofcurl -I
?
â NerdOfLinux
Apr 24 at 13:54
@NerdOfLinux question edited.
â user9303970
Apr 27 at 7:08
Can we get thefastcgi_pass
directive in your virtual host, and the output ofsudo fuser 9000/tcp
along withsudo grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
?
â NerdOfLinux
Apr 27 at 13:49
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm having trouble getting my site to work after trying to implement Nginx caching.
I use Ubuntu 16.04 (xenial), Nginx (1.10.3), PHP-FPM (7.0) and WordPress.
Port 9000 (for php-fpm) is unfiltered by UFW.
Reproducing my environment
1 - setting confs:
nginx.conf
default conf
virtual host
/etc/php/7.0/fpm/pool.d/www.conf (comments omitted)
2 - Creating a cache dir:
mkdir -p /var/cache/nginx/fastcgi_temp/cache/
chmod 755 /var/cache/nginx/fastcgi_temp/cache/
chown www-data:www-data /var/cache/nginx/fastcgi_temp/cache/
3 - Server restart:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
4- Error and debug tries:
*1 connect() failed (111: Connection refused) while connecting to upstream,
client: MY_IP_ADDRESS, server: example.com, request: "GET /
HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000".
The browser gives:
502 Bad Gateway nginx/1.10.3 (Ubuntu)
Debug:
/etc/init.d/php*-fpm status
brings:
â php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-27 07:09:28 UTC; 3s ago
Process: 16336 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 16346 (php-fpm7.0)
Status: "Ready to handle connections"
My question
Why is the connection refused and my site is down?
Update for NerdOfLinux:
+ curl -I example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
And
grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
+ grep --color=auto -v ';'
+ grep --color=auto listen /etc/php/7.0/fpm/pool.d/www.conf
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
16.04 server php nginx cache
I'm having trouble getting my site to work after trying to implement Nginx caching.
I use Ubuntu 16.04 (xenial), Nginx (1.10.3), PHP-FPM (7.0) and WordPress.
Port 9000 (for php-fpm) is unfiltered by UFW.
Reproducing my environment
1 - setting confs:
nginx.conf
default conf
virtual host
/etc/php/7.0/fpm/pool.d/www.conf (comments omitted)
2 - Creating a cache dir:
mkdir -p /var/cache/nginx/fastcgi_temp/cache/
chmod 755 /var/cache/nginx/fastcgi_temp/cache/
chown www-data:www-data /var/cache/nginx/fastcgi_temp/cache/
3 - Server restart:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
4- Error and debug tries:
*1 connect() failed (111: Connection refused) while connecting to upstream,
client: MY_IP_ADDRESS, server: example.com, request: "GET /
HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000".
The browser gives:
502 Bad Gateway nginx/1.10.3 (Ubuntu)
Debug:
/etc/init.d/php*-fpm status
brings:
â php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-27 07:09:28 UTC; 3s ago
Process: 16336 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 16346 (php-fpm7.0)
Status: "Ready to handle connections"
My question
Why is the connection refused and my site is down?
Update for NerdOfLinux:
+ curl -I example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
And
grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
+ grep --color=auto -v ';'
+ grep --color=auto listen /etc/php/7.0/fpm/pool.d/www.conf
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
16.04 server php nginx cache
16.04 server php nginx cache
edited Apr 27 at 13:58
asked Apr 13 at 9:49
user9303970
81112
81112
Can we get the output ofcurl -I
?
â NerdOfLinux
Apr 24 at 13:54
@NerdOfLinux question edited.
â user9303970
Apr 27 at 7:08
Can we get thefastcgi_pass
directive in your virtual host, and the output ofsudo fuser 9000/tcp
along withsudo grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
?
â NerdOfLinux
Apr 27 at 13:49
add a comment |Â
Can we get the output ofcurl -I
?
â NerdOfLinux
Apr 24 at 13:54
@NerdOfLinux question edited.
â user9303970
Apr 27 at 7:08
Can we get thefastcgi_pass
directive in your virtual host, and the output ofsudo fuser 9000/tcp
along withsudo grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
?
â NerdOfLinux
Apr 27 at 13:49
Can we get the output of
curl -I
?â NerdOfLinux
Apr 24 at 13:54
Can we get the output of
curl -I
?â NerdOfLinux
Apr 24 at 13:54
@NerdOfLinux question edited.
â user9303970
Apr 27 at 7:08
@NerdOfLinux question edited.
â user9303970
Apr 27 at 7:08
Can we get the
fastcgi_pass
directive in your virtual host, and the output of sudo fuser 9000/tcp
along with sudo grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
?â NerdOfLinux
Apr 27 at 13:49
Can we get the
fastcgi_pass
directive in your virtual host, and the output of sudo fuser 9000/tcp
along with sudo grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
?â NerdOfLinux
Apr 27 at 13:49
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
The issue at play is a misconfiguration by you of the nginx fastcgi_pass
directive to point at a nonexistent backend/upstream gateway.
Since 14.10 (or was it 15.10, I dont remember now exactly) php-fpm
listens on a local UNIX socket and not TCP port 9000 by default. I know this because I spearheaded the effort to make this change in Ubuntu and Debian for the defaults for FPM, and it was accepted in the packaging. And I know this is your setup because of the listen =
line of your FPM www.conf
which says its listening on a socket.
Put unix:/run/php/php7.0-fpm.sock
in your fastcgi_pass
directive in the nginx
server block, and not the 127.0.0.1:9000
you have. That should then allow it to work properly because the correct PHP upstream gateway is then used.
add a comment |Â
up vote
-1
down vote
check in your php-fpm pool definition which is to be found in /etc/php/7.0/fpm/pool.d
User www-data is used to run php-fpm:
user = www-data
group = www-data
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
Core issue is that OP didnt pay attention to FPM'slisten
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample insites-available/default
from the package on a clean install of NGINX) have both thephp-cgi
andphp-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.
â Thomas Wardâ¦
Apr 27 at 11:38
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The issue at play is a misconfiguration by you of the nginx fastcgi_pass
directive to point at a nonexistent backend/upstream gateway.
Since 14.10 (or was it 15.10, I dont remember now exactly) php-fpm
listens on a local UNIX socket and not TCP port 9000 by default. I know this because I spearheaded the effort to make this change in Ubuntu and Debian for the defaults for FPM, and it was accepted in the packaging. And I know this is your setup because of the listen =
line of your FPM www.conf
which says its listening on a socket.
Put unix:/run/php/php7.0-fpm.sock
in your fastcgi_pass
directive in the nginx
server block, and not the 127.0.0.1:9000
you have. That should then allow it to work properly because the correct PHP upstream gateway is then used.
add a comment |Â
up vote
2
down vote
accepted
The issue at play is a misconfiguration by you of the nginx fastcgi_pass
directive to point at a nonexistent backend/upstream gateway.
Since 14.10 (or was it 15.10, I dont remember now exactly) php-fpm
listens on a local UNIX socket and not TCP port 9000 by default. I know this because I spearheaded the effort to make this change in Ubuntu and Debian for the defaults for FPM, and it was accepted in the packaging. And I know this is your setup because of the listen =
line of your FPM www.conf
which says its listening on a socket.
Put unix:/run/php/php7.0-fpm.sock
in your fastcgi_pass
directive in the nginx
server block, and not the 127.0.0.1:9000
you have. That should then allow it to work properly because the correct PHP upstream gateway is then used.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The issue at play is a misconfiguration by you of the nginx fastcgi_pass
directive to point at a nonexistent backend/upstream gateway.
Since 14.10 (or was it 15.10, I dont remember now exactly) php-fpm
listens on a local UNIX socket and not TCP port 9000 by default. I know this because I spearheaded the effort to make this change in Ubuntu and Debian for the defaults for FPM, and it was accepted in the packaging. And I know this is your setup because of the listen =
line of your FPM www.conf
which says its listening on a socket.
Put unix:/run/php/php7.0-fpm.sock
in your fastcgi_pass
directive in the nginx
server block, and not the 127.0.0.1:9000
you have. That should then allow it to work properly because the correct PHP upstream gateway is then used.
The issue at play is a misconfiguration by you of the nginx fastcgi_pass
directive to point at a nonexistent backend/upstream gateway.
Since 14.10 (or was it 15.10, I dont remember now exactly) php-fpm
listens on a local UNIX socket and not TCP port 9000 by default. I know this because I spearheaded the effort to make this change in Ubuntu and Debian for the defaults for FPM, and it was accepted in the packaging. And I know this is your setup because of the listen =
line of your FPM www.conf
which says its listening on a socket.
Put unix:/run/php/php7.0-fpm.sock
in your fastcgi_pass
directive in the nginx
server block, and not the 127.0.0.1:9000
you have. That should then allow it to work properly because the correct PHP upstream gateway is then used.
edited Apr 27 at 14:18
answered Apr 27 at 11:31
Thomas Wardâ¦
41.4k23112166
41.4k23112166
add a comment |Â
add a comment |Â
up vote
-1
down vote
check in your php-fpm pool definition which is to be found in /etc/php/7.0/fpm/pool.d
User www-data is used to run php-fpm:
user = www-data
group = www-data
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
Core issue is that OP didnt pay attention to FPM'slisten
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample insites-available/default
from the package on a clean install of NGINX) have both thephp-cgi
andphp-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.
â Thomas Wardâ¦
Apr 27 at 11:38
add a comment |Â
up vote
-1
down vote
check in your php-fpm pool definition which is to be found in /etc/php/7.0/fpm/pool.d
User www-data is used to run php-fpm:
user = www-data
group = www-data
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
Core issue is that OP didnt pay attention to FPM'slisten
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample insites-available/default
from the package on a clean install of NGINX) have both thephp-cgi
andphp-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.
â Thomas Wardâ¦
Apr 27 at 11:38
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
check in your php-fpm pool definition which is to be found in /etc/php/7.0/fpm/pool.d
User www-data is used to run php-fpm:
user = www-data
group = www-data
check in your php-fpm pool definition which is to be found in /etc/php/7.0/fpm/pool.d
User www-data is used to run php-fpm:
user = www-data
group = www-data
answered Apr 24 at 8:08
Aditya
16427
16427
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
Core issue is that OP didnt pay attention to FPM'slisten
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample insites-available/default
from the package on a clean install of NGINX) have both thephp-cgi
andphp-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.
â Thomas Wardâ¦
Apr 27 at 11:38
add a comment |Â
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
Core issue is that OP didnt pay attention to FPM'slisten
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample insites-available/default
from the package on a clean install of NGINX) have both thephp-cgi
andphp-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.
â Thomas Wardâ¦
Apr 27 at 11:38
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
That's exactly my definition there.
â user9303970
Apr 27 at 7:07
Core issue is that OP didnt pay attention to FPM's
listen
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample in sites-available/default
from the package on a clean install of NGINX) have both the php-cgi
and php-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.â Thomas Wardâ¦
Apr 27 at 11:38
Core issue is that OP didnt pay attention to FPM's
listen
line and therefore has NGINX handing off to the wrong location. I see this error all the time its why the actual default package configs (the sample in sites-available/default
from the package on a clean install of NGINX) have both the php-cgi
and php-fpm
fastcgi_pass
options in the default example config with the FPM one uncommented by default.â Thomas Wardâ¦
Apr 27 at 11:38
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1024606%2ffailed-to-implement-nginx-caching-connection-refused%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Can we get the output of
curl -I
?â NerdOfLinux
Apr 24 at 13:54
@NerdOfLinux question edited.
â user9303970
Apr 27 at 7:08
Can we get the
fastcgi_pass
directive in your virtual host, and the output ofsudo fuser 9000/tcp
along withsudo grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
?â NerdOfLinux
Apr 27 at 13:49