Failed to implement Nginx caching - connection refused

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








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









share|improve this question























  • 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 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














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









share|improve this question























  • 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 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












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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 27 at 13:58

























asked Apr 13 at 9:49









user9303970

81112




81112











  • 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 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 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 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 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










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted
+50










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.






share|improve this answer





























    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






    share|improve this answer




















    • 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











    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted
    +50










    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.






    share|improve this answer


























      up vote
      2
      down vote



      accepted
      +50










      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.






      share|improve this answer
























        up vote
        2
        down vote



        accepted
        +50







        up vote
        2
        down vote



        accepted
        +50




        +50




        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 27 at 14:18

























        answered Apr 27 at 11:31









        Thomas Ward♦

        41.4k23112166




        41.4k23112166






















            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






            share|improve this answer




















            • 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















            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






            share|improve this answer




















            • 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













            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






            share|improve this answer












            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







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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'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

















            • 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
















            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


















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Which professions warranted travel in Medieval times?

            How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

            Trouble downloading packages list due to a “Hash sum mismatch” error