curl: (7) Failed to connect to localhost port 443: Connection refused



  • Can anyone help with this?

    Tried to curl to https://localhost when I received this error. I setup nginx ssl as follows.

       # Listen on port 443 using SSL and make it the default server
        listen 443 default_server ssl;
    
        # Specify the path of your .crt and .key files
        ssl on;
        ssl_certificate     /etc/ssl/private/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;
    
        # Enable session caching, increase session timeout
        ssl_session_cache shared:SSL:20m;
        ssl_session_timeout 60m;
    
        # Disable SSL in favor of TLS (safer)
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    
    $ curl  https://localhost 
    curl: (7) Failed to connect to localhost port 443: Connection refused
    


  • @mountaing Need more info, Where did you setup the ssl configuration? which file did you use? and what are you running?



  • @blackrhino I am setting up a wordpress website, I put the ssl configuration into /etc/nginx/conf.d/default.conf. I also get a blank page if I go to the browser and enter https://localhost. My certs are in /etc/ssl/private/localhost.crt and /etc/ssl/private/localhost.key they are accessible by nginx.

    My wordpress configuration is in /etc/nginx/sites-enabled/wordpress.conf
    and I should have mentioned that http://localhost works fine. I can see my wordpress home page.



  • @mountaing As you are trying to get ssl working for wordpress and already have a config file for it, move your ssl config to /etc/nginx/sites-enabled/wordpress.conf under the line that read listen 80 like this:

    cat wordpress.conf        
    server { 
       # Listen on all network interfaces on port 80 
       listen 80; 
       # Listen on port 443 using SSL and make it the default server
        listen 443 default_server ssl;
    
        # Specify the path of your .crt and .key files
        ssl on;
        ssl_certificate     /etc/ssl/private/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;
    
        # Enable session caching, increase session timeout
        ssl_session_cache shared:SSL:20m;
        ssl_session_timeout 60m;
    
        # Disable SSL in favor of TLS (safer)
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    

    Do a restart or reload of nginx. I just want to add as you are doing everything on localhost, there should be not firewall blocking the port, if however you move to a proper domain name, the firewall will need to be configured to allow 80 and 443.



  • @blackrhino Hi There, I moved the ssl contents to the wordpress.conf that makes sense, but I realised I made a big mistake, I had commented out one of the include entries in nginx.conf file, so it was never getting picked up. Sorry about that to take up your time, but the your suggestion actually gave me the clue, so thank for the help.

        #include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*.conf;
    

    This is the entire wordpress.conf that worked.

    server { 
       # Listen on all network interfaces on port 80 
       listen 80; 
       # Listen on port 443 using SSL and make it the default server
        listen 443 default_server ssl;
    
        # Specify the path of your .crt and .key files
        ssl_certificate     /etc/ssl/private/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;
    
        # Enable session caching, increase session timeout
        ssl_session_cache shared:SSL:20m;
        ssl_session_timeout 60m;
    
        # Disable SSL in favor of TLS (safer)
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    
     
       # Specify the host name(s) that will match the site 
       # The following value allows both www. and no subdomain 
       server_name geeky; 
        
       # Set the path of your WordPress files 
       root /home/wordpress/www; 
     
       # Automatically load index.php 
       index index.php; 
        
       # Saves client request body into files, cleaning up afterwards 
       client_body_in_file_only clean; 
       client_body_buffer_size 32K; 
     
       # Allow uploaded files up to 300 megabytes 
       client_max_body_size 300M; 
        
       # Automatically close connections if no data is  
       # transmitted to the client for a period of 10 seconds 
       send_timeout 10s; 
        
       # The rest of the configuration (location blocks)  
       # is found below 
       # The following applies to static files:  
       # images, CSS, javascript 
       location ~* ^.+.(jpg|jpeg|png|gif|ico|css|js)$ { 
             access_log off; # Disable logging 
             # Allow client browsers to cache files  
             # for a long period of time 
             expires 180d;  
       } 
     
       # The following applies to every request 
       location / { 
          # Try serving the requested URI: 
          # - If the file does not exist, append / 
          # - If the directory does not exist,  
          # redirect to /index.php forwarding the request URI 
          # and other request arguments 
             try_files $uri $uri/ /index.php?q=$uri&$args; 
       } 
        
       # The following applies to every PHP file 
       location ~ .php$ { 
             # Ensure file really exists 
                if (!-e $request_filename) { 
                      return 404; 
                } 
                # Pass the request to your PHP-FPM backend 
                fastcgi_pass 127.0.0.1:9000; 
             fastcgi_index index.php; 
             fastcgi_param SCRIPT_FILENAME /home/wordpress/www$fastcgi_script_name; 
             include fastcgi_params; 
       } 
    } 
    

    I have a self-signed cert hence the warning but the curl test worked.

    $ curl https://localhost              
    curl: (60) SSL certificate problem: self signed certificate
    More details here: https://curl.haxx.se/docs/sslcerts.html
    
    curl failed to verify the legitimacy of the server and therefore could not
    establish a secure connection to it. To learn more about this situation and
    how to fix it, please visit the web page mentioned above.
    

Log in to reply
 

© Lightnetics 2024