CURL receive "empty reply from server", but browser receive response. Why? - django

I set up rest-api server. (Django 1.11 + NGINX + Gunicorn + Postgresql 9.6)
For testing, I developed simple API. Get request URL /test, then respond "success" string. In web browser, it worked well.
But when I request same url with CURL, I receive "curl: (52) Empty reply from server". I tried curl on other remote server, and I tried curl http://127.0.0.1/test on that server. Both didn't not work. I received "curl: (52) Empty reply from server".
Why it work in web browser, and it not work in CURL? Where should I check? NGIMX? Django? I checked firewell.
Sorry for poor english. Thanks!
UPDATE:
I tried the following,
$ curl -vv http://127.0.0.1/test/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET /test/ HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.58.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

First add -vv to the curl command to see what is happening with the connection. If it says server redirection is happening, add -L to solve the problem.

Related

localhost:8000 working but mywebsite:8000 with etc/hosts modified doesn't work

Everything is in the title: I'm launching my webserver (Django / Python) on port 8000.
/home/olivier/my_venv3.8/bin/python3 /home/olivier/pycharm-2018.1.3/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 40761 --file /home/olivier/projects/evalr/manage.py runserver 8000
pydev debugger: process 5923 is connecting
Connected to pydev debugger (build 193.5662.61)
http://evalr.hqf.fr:8000/fr/assistant/
http://evalr.hqf.fr:8000/fr/sessions/
pydev debugger: process 5935 is connecting
http://evalr.hqf.fr:8000/fr/assistant/
http://evalr.hqf.fr:8000/fr/sessions/
Watching for file changes with StatReloader
Performing system checks...
I've added in my /etc/hosts this line : 127.0.1.1 evalr.hqf.fr and when I ping it, it correctly shows "127.0.0.1"
When I try go on http://evalr.hqf.fr:8000 I get connection refused and when I try to go on http:/localhost:8000 it works.
The problem is that when I try to go on http://evalr.hqf.fr:8000 I dont have any trace on the server side, i.e. it stays here:
System check identified no issues (0 silenced).
January 03, 2020 - 20:41:31
Django version 3.0.2, using settings 'evalr.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
And when I go on http://127.0.0.1:8000/ I get a log of every single access like:
[03/Jan/2020 20:47:42] "GET /fr/sessions/ HTTP/1.1" 302 0
[03/Jan/2020 20:47:42] "GET /fr/login/?next=/fr/sessions/ HTTP/1.1" 200 7031
[03/Jan/2020 20:47:43] "GET /static/vendors/css/all.min.css HTTP/1.1" 200 54456
................ blabla............;
[03/Jan/2020 20:47:43] "GET /favicon.ico HTTP/1.1" 301 0
I've even tried to reboot (even though I'm on Linux, which talks by itself - no reboot needed), so I'm stuck because everything should work fine. What am I missing?
That is because in /etc/hosts it should be 127.0.0.1 instead
Also check the ALLOWED_HOSTS and you could try running it with: python manage.py runserver 0.0.0.0:8000
The fact that you get a connection refused when using the hostname, and do not see any logging from your application, makes me think that you are dealing with DNS caching. My favorite way to test this is using curl, since it can show you both the IP address and response of an HTTP request. Try the following command:
curl -Iv -X GET http://evalr.hqf.fr:8000
Did it resolve to 127.0.0.1? If so, did you get a response? If so, did you see logs in your application?
If the answer to these question is yes, then try to clear the DNS and browser cache.

ec2 instance different behaviour on each machine

Recently I am encountering an issue with one of the ec2 machines where I am unable to do curl or telnet.
One ec2 machine with same config and same subnet is working as expected. Other machines not connecting. even curl request is also not working. I have verified other domains it's working as expected.
example :
On one ec2 machine
ubuntu#xxxxx-a1:~$ telnet 59.162.167.9 80
Trying 59.162.167.9...
Connected to 59.162.167.9.
Escape character is '^]'.
on other machines even after creating the image from the first machine
ubuntu#xxxxx-a4:~$ telnet 59.162.167.9 80
Trying 59.162.167.9...
even curl request is also not working. I have verified other domains its working as expected.
Our public IP is the same for all machines which are configured at nat gateway.
ubuntu#xxxxx-a4:~$ curl -v http://api-openhouse.imimobile.com/1/obd/thirdpartycall/callSessions
Trying 59.162.167.9...
on the first machine
ubuntu#xxxxx-a1:~$ curl -v http://api-openhouse.imimobile.com/1/obd/thirdpartycall/callSessions
Trying 59.162.167.9...
Connected to api-openhouse.imimobile.com (59.162.167.9) port 80 (#0)
GET /1/obd/thirdpartycall/callSessions HTTP/1.1
Host: api-openhouse.imimobile.com
User-Agent: curl/7.47.0
Accept: /
< HTTP/1.1 202 Accepted
< Server: nginx
< Date: Wed, 24 Apr 2019 16:30:47 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
<
Connection #0 to host api-openhouse.imimobile.com left intact
Verified my public ip
ubuntu#xxxx-a1:~$ curl ifconfig.co
34.194.201.11
ubuntu#xxxxx-a4:~$ curl ifconfig.co
34.194.201.11
I have validated different approaches and verified network and security-related issues but didn't succeed, even I have created new image still it didn't work.
One ec2 machine with same config and same subnet is working as expected. Other machines not connecting. even curl request is also not working. I have verified other domains it's working as expected.

Access CouchDB with external URL

I have installed CouchDB in my AWS server. When I run the command
curl localhost:5984
then I got a response like:
{"couchdb":"Welcome","uuid":"b7a38141c61a37390945a99fd88f0015","version":"1.6.0","vendor":{"version":"15.10","name":"Ubuntu"}}
But when I run this command:
curl ip_address:5984
then it gives:
curl: (7) Failed to connect to Ip-address port 5984: Connection refused
Your CouchDB is not listening on all interfaces. Edit your couch.ini file and modify the line to:
bind_address = 0.0.0.0
and restart couch service. If it still doesn't work, post the output of netstat -plan | grep 5984.
Clearly explained here: CouchDB HTTP Server
bind_address : Defines the IP address by which CouchDB will be accessible:
[httpd]
bind_address = 127.0.0.1
To let CouchDB listen any available IP address, just set up 0.0.0.0 value:
[httpd]
bind_address = 0.0.0.0

Sending Email With libcurl fails Over Exchange Server

I am attempting to send a simple email message using libcurl in C++ over a MS Exchange server. The program seems to connect with the server, authenticate correctly, but fails with error 500 - unknown command when attempting to send the package.
I have verified the server address, that libcurl was compiled with SSL support, NTLM is supported authentication type, and all the email addresses are valid.
Checking the CURL version returns:
curl 7.37.1 (armv5tejl-unknown-linux-gnueabi) libcurl/7.37.1 OpenSSL/0.9.8o zlib/1.2.3.4
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz
And the program reports the following:
* Rebuilt URL to: mail.domain.net:587/
* Hostname was NOT found in DNS cache
* Trying 192.168.0.114...
* Connected to mail.domain.net (192.168.0.114) port 587 (#0)
* Server auth using NTLM with user 'redmine'
> PUT / HTTP/1.1
Authorization: NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=
Host: mail.iem.net:587
Accept: */*
Content-Length: 0
220 mail.domain.net Microsoft ESMTP MAIL Service ready at Fri, 22 Aug 2014 15:20:09 -0400
500 5.3.3 Unrecognized command
500 5.3.3 Unrecognized command
500 5.3.3 Unrecognized command
500 5.3.3 Unrecognized command
500 5.3.3 Unrecognized command
421 4.7.0 Too many errors on this connection, closing transmission channel
* Connection #0 to host mail.iem.net left intact
I'm using the following connection settings in the program:
curl_easy_setopt(this->curl,CURLOPT_URL, this->address.c_str());
curl_easy_setopt(this->curl,CURLOPT_USERNAME,this->username.c_str());
curl_easy_setopt(this->curl,CURLOPT_PASSWORD,this->username.c_str());
curl_easy_setopt(this->curl,CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_easy_setopt(this->curl,CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_easy_setopt(this->curl,CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(this->curl,CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(this->curl,CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(this->curl,CURLOPT_UPLOAD, 1L);
curl_easy_setopt(this->curl, CURLOPT_VERBOSE, 1L);
Any suggestions would be greatly appreciated!

502 on Nginx after start CSF

I've installed gunicorn, django and nginx as described in this tutorial.
I've developed a function in django that adds a user in my database and it works perfectly!!
Now I've installed CSF (Config Server Firewall) and if I run it csf -r, the same function for adding a user doesn't work.
I see, in the error log of Nginx, this raw:
*2014/06/25 10:11:04 [error] 5396#0: *19 upstream prematurely closed connection while reading response header from upstream, client: 79.35.50.121, server: [MY_SERVER_NAME], request: POST /django/registerClient HTTP/1.1, upstream: [MY_IP_SERVER]:8001/django/registerClient, host: [MY_IP_SERVER]*
I underline that the function work without star csf.
Can anyone can explain to me why I get this problem?