Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    Nginx: connect() failed (111: Connection refused) while connecting to upstream

    Linux
    nginx php server ubuntu
    3
    7
    6041
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lkdev
      lkdev last edited by

      Hi guys, i'm new to nginx, i am getting 502 gateway timeout error. i want to execute php with nginx server. my server is running on ubuntu 18.04

      Nginx error log

      2019/01/05 09:17:59 [error] 30189#30189: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 95.235.148.111, server: mysite.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mysite.com"
      
      

      My server block is

      server {
              listen 80;
              root /var/www/html;
              index index.php index.html index.htm index.nginx-debian.html;
              server_name mysite.com;
      
              location / {
                      try_files $uri $uri/ =404;
              }
      
              location ~ \.php$ {
                     fastcgi_pass   127.0.0.1:9000;
                     fastcgi_param  SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
                     include        fastcgi_params;
                  }
      
              location ~ /\.ht {
                      deny all;
              }
      }
      
      
      crxssrazr93 1 Reply Last reply Reply Quote 0
      • crxssrazr93
        crxssrazr93 @lkdev last edited by

        @lkdev

        Make sure php-fpm is already running on the background...

        Then, change your listen 80; to listen 127.0.0.1; .

        lkdev 2 Replies Last reply Reply Quote 3
        • ciaompe
          ciaompe last edited by ciaompe

          Simply, open the following path to your php5-fpm (if you php 7 then open php 7 fpm)

          Php 5

          sudo nano /etc/php5/fpm/pool.d/www.conf
          

          Php 7

          sudo nano /etc/php/7.2/fpm/pool.d/www.conf
          

          Then find this line and uncomment it:

          listen.allowed_clients = 127.0.0.1
          

          Also comment below line


          Php 5

          ;listen = /var/run/php5-fpm.sock 
          

          Php 7

          ;listen = /run/php/php7.2-fpm.sock
          

          and add


          listen = 9000
          

          after you make the modifications, all you need to restart or reload both Nginx and Php fpm

          Php 5

          sudo service php5-fpm restart
          

          Php 7

          sudo service php7.2-fpm restart
          

          Nginx

          sudo service nginx restart
          
          lkdev 1 Reply Last reply Reply Quote 0
          • lkdev
            lkdev @crxssrazr93 last edited by

            @crxssrazr93

            Thnx Bro.

            1 Reply Last reply Reply Quote 0
            • lkdev
              lkdev @ciaompe last edited by

              @ciaompe

              Thnx bro, i'll follow the steps

              1 Reply Last reply Reply Quote 0
              • lkdev
                lkdev @crxssrazr93 last edited by

                @crxssrazr93 said in Nginx: connect() failed (111: Connection refused) while connecting to upstream:

                @lkdev

                Make sure php-fpm is already running on the background...

                Then, change your listen 80; to listen 127.0.0.1; .

                @ciaompe said in Nginx: connect() failed (111: Connection refused) while connecting to upstream:

                Simply, open the following path to your php5-fpm (if you php 7 then open php 7 fpm)

                Php 5

                sudo nano /etc/php5/fpm/pool.d/www.conf
                

                Php 7

                sudo nano /etc/php/7.2/fpm/pool.d/www.conf
                

                Then find this line and uncomment it:

                listen.allowed_clients = 127.0.0.1
                

                Also comment below line


                Php 5

                ;listen = /var/run/php5-fpm.sock 
                

                Php 7

                ;listen = /run/php/php7.2-fpm.sock
                

                and add


                listen = 9000
                

                after you make the modifications, all you need to restart or reload both Nginx and Php fpm

                Php 5

                sudo service php5-fpm restart
                

                Php 7

                sudo service php7.2-fpm restart
                

                Nginx

                sudo service nginx restart
                

                Guys this works. thanks aganin and lankadevelopers thank you very much

                crxssrazr93 1 Reply Last reply Reply Quote 0
                • crxssrazr93
                  crxssrazr93 @lkdev last edited by

                  @lkdev said in Nginx: connect() failed (111: Connection refused) while connecting to upstream:

                  @crxssrazr93 said in Nginx: connect() failed (111: Connection refused) while connecting to upstream:

                  @lkdev

                  Make sure php-fpm is already running on the background...

                  Then, change your listen 80; to listen 127.0.0.1; .

                  @ciaompe said in Nginx: connect() failed (111: Connection refused) while connecting to upstream:

                  Simply, open the following path to your php5-fpm (if you php 7 then open php 7 fpm)

                  Php 5

                  sudo nano /etc/php5/fpm/pool.d/www.conf
                  

                  Php 7

                  sudo nano /etc/php/7.2/fpm/pool.d/www.conf
                  

                  Then find this line and uncomment it:

                  listen.allowed_clients = 127.0.0.1
                  

                  Also comment below line


                  Php 5

                  ;listen = /var/run/php5-fpm.sock 
                  

                  Php 7

                  ;listen = /run/php/php7.2-fpm.sock
                  

                  and add


                  listen = 9000
                  

                  after you make the modifications, all you need to restart or reload both Nginx and Php fpm

                  Php 5

                  sudo service php5-fpm restart
                  

                  Php 7

                  sudo service php7.2-fpm restart
                  

                  Nginx

                  sudo service nginx restart
                  

                  Guys this works. thanks aganin and lankadevelopers thank you very much

                  Anytime mate xD

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post

                  2
                  Online

                  3.7k
                  Users

                  1.3k
                  Topics

                  5.3k
                  Posts

                  • Privacy
                  • Terms & Conditions
                  • Donate

                  © Copyrights and All right reserved Lanka Developers Community

                  Powered by Axis Technologies (PVT) Ltd

                  Made with in Sri Lanka

                  | |