• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Let nginx listen to 127.0.0.1 for default domain

BobClaas

Basic Pleskian
-- update --
Issue found: nginx aint listening to 127.0.0.1 for the default domain (/etc/nginx/plesk.conf.d/ip_default/****.nl.conf).
Manualy editing the vhost file with a listen added fixed it temporary.
Need help with solution how to fix this the right way.
See post #6


I've got webapplication that uses curl to access other modules of itself on de same plesk server, same domain. But the connection is refused.

curl -v --ipv4 -I 'https://mydomain.nl'
* About to connect() to mydomain.nl port 443 (#0)
* Trying 127.0.0.1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host


while
curl -v --ipv4 -I 'https://www.mydomain.nl'
* About to connect() to www.mydomain.nl port 443 (#0)
* Trying 33.34.35.36 (my public ip)... connected
* Connected to www.mydomain.nl (my public ip) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate:
* subject: bla bla bla
* start date: Apr 13 00:00:00 2016 GMT
* expire date: Apr 13 23:59:59 2017 GMT
* common name: mydomain.nl
* issuer: bla bla
> HEAD / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: www.mydomain.nl
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Server: nginx
Server: nginx
< Date: Wed, 04 Jan 2017 19:57:14 GMT
Date: Wed, 04 Jan 2017 19:57:14 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 178
Content-Length: 178
< Connection: keep-alive
Connection: keep-alive
< Location: https://mydomain.nl/
Location: https://mydomain.nl/

<
* Connection #0 to host www.mydomain.nl left intact
* Closing connection #0


and other domains on the server work. My "domain.nl" without "www" is the name of the server. My guess is that my domain is translated throught the hostfile to "localhost" and nginx is not listening to localhost.

(if im on the right track) Is there a way to let nginx also listen to the localhost
 
Last edited:
My guess is that my domain is translated throught the hostfile to "localhost" and nginx is not listening to localhost.

No, curl should be able to connect to all local domains on ports 80 and 443. I have tested your curl request on an Onyx machine with a local URL. It did work with both, port 80 and 443.

If curl cannot connect, check whether the local IP or localhost (127.0.0.1) is blocked by fail2ban and whether a firewall rule or ModSecurity firewall might block access.
 
No, curl should be able to connect to all local domains on ports 80 and 443. I have tested your curl request on an Onyx machine with a local URL. It did work with both, port 80 and 443.

If curl cannot connect, check whether the local IP or localhost (127.0.0.1) is blocked by fail2ban and whether a firewall rule or ModSecurity firewall might block access.
Did u try to curl to the same hostname of your server?

This would be strange since i can curl to all local websites but not to the one with the same name as the server. Even if i use www. before it, it works. Due the fact i cant change the curl request of the third party software i cant change the url. So i must get the curl working for the http://mydomain.nl url (without www).

Seems all local domains are translated to the external ip and there nginx is listening. But this url isn't cause of the servername.

To be sure i disabled fail2ban and ModSecurity. Same result.


netstat -tulpn|grep nginx
tcp 0 0 mypublicip:80 0.0.0.0:* LISTEN 28113/nginx
tcp 0 0 mypublicip:443 0.0.0.0:* LISTEN 28113/nginx

nginx is not listening to localhost. Don't know how to fix this.
 
Last edited:
I cannot confirm that. On my test machine I have created a subscription and named it like the host's domain. I am testing locally from the console with
# curl --head http://my-server-domain

And get a correct response:
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 06 Jan 2017 14:39:23 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.6.29
X-Powered-By: PleskLin

(Page content is delivered, too).

The problem must be elsewhere. Could it be possible that the website evaluates the caller and responds with a redirect in case that the caller is an unknown source?
 
I think that would give an connection but with a HTTP/1.1 401 or 403 or whatever response wouldnt it?
What is the result of "netstat -tulpn|grep nginx" on your server?
 
Found out that i was on the right track. nginx not listening to the localhost for the default domain.
By manualy editing the vhost file i've got the curl working.
File edited is /etc/nginx/plesk.conf.d/ip_default/****.nl.conf

How to edit the vhost file correctly for the default server domain to let it listen to 127.0.0.1?
 
What i did to fix this is:
copy the template nginxDomainVhostIpDefault.php to custom

Added these lines:
PHP:
<?php //$VAR->domain->asciiName = "localhost:433" ?>
<?php $ipAddress->escapedAddress = "localhost" ?>

<?php echo $VAR->includeTemplate('domain/nginxDomainVirtualHost.php',
    array(
        'ssl' => true,
        'frontendPort' => $VAR->server->nginx->httpsPort,
        'backendPort' => $VAR->server->webserver->httpsPort,
        'documentRoot' => $VAR->domain->physicalHosting->httpsDir,
        'ipAddress' => $ipAddress,
        'default' => true,
    )) ?>

<?php echo $VAR->includeTemplate('domain/nginxDomainVirtualHost.php',
    array(
        'ssl' => false,
        'frontendPort' => $VAR->server->nginx->httpPort,
        'backendPort' => $VAR->server->webserver->httpPort,
        'documentRoot' => $VAR->domain->physicalHosting->httpDir,
        'ipAddress' => $ipAddress,
        'default' => true,
    )) ?>
 
I cannot confirm that. On my test machine I have created a subscription and named it like the host's domain. I am testing locally from the console with
# curl --head http://my-server-domain

And get a correct response:
HTTP/1.1 200 OK

I can confirm that my server gives a "curl: (7) couldn't connect to host" when calling "curl --head http://my-server-main-domain" but all other domains hosted on the server work correctly. I haven't needed it to work before, but I know it has had this quirk for quite a while now. I've often wondered why it didn't work correctly. I'm running CentOS 6.9, Apache 2.2, and nginx as a proxy. I'm not keen on making a custom template just to fix it.
 
Back
Top