# TCP Connection

**URL:** <https://www.ruby-forum.com/t/tcp-connection/244203>\
**Category:** NGINX\
**Created:** [March 4, 2016, 5:21pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203 "2016-03-04T17:21:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [March 4, 2016, 5:21pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/1 "2016-03-04T17:21:02Z")

</div>

Hi All,

If I’m sending this email to wrong list, apologies and give me the good  
one.

I have one embedded application which needs to connect via TCP and send  
an HTTP request.  
We run Nginx on Ubuntu 14.04.

I can connect and persist, but once the packet is sent, I get HTTP 400  
without any log and without web server taking the request.

I think it is a deeper level on Nginx but having hard to find a good  
answer.

Hope somebody can help.

Thanks

Giulio

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 5:25pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/2 "2016-03-04T17:25:43Z")

</div>

On Friday 04 March 2016 17:20:18 Giulio L. wrote:

> Hope somebody can help.

[..]

The reason of 400 is usually logged on “info” level in error\_log.

See: [Core functionality](http://nginx.org/r/error_log)

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 5:42pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/3 "2016-03-04T17:42:04Z")

</div>

Thank you for your answer.

Here is my log after the request, my request, my response and my  
nginx.conf

root@vps190138:~# cat /var/log/nginx-error.log  
2016/03/04 15:49:02 [notice] 8990#0: using the “epoll” event method  
2016/03/04 15:49:02 [notice] 8990#0: nginx/1.8.1  
2016/03/04 15:49:02 [notice] 8990#0: OS: Linux 3.13.0-66-generic  
2016/03/04 15:49:02 [notice] 8990#0: getrlimit(RLIMIT\_NOFILE): 1024:4096  
2016/03/04 15:49:02 [notice] 8991#0: start worker processes  
2016/03/04 15:49:02 [notice] 8991#0: start worker process 8993

#REQUEST  
AT+CIPSTART=“TCP”, “[myhost.com](http://myhost.com)”,“80”  
AT+CIPSEND=150

POST /devices/deviceRegister HTTP/1.1  
Host: [myhost.com](http://myhost.com)  
Cache-Control: no-cache  
Content-Type: application/json  
Content-Length:14

{“IMEI”:“aa”}

#RESPONSE  
SEND OK  
HTTP/1.1 400 Bad Request  
Server: nginx/1.8.1  
Date: Fri, 04 Mar 2016 15:52:21 GMT  
Content-Type: text/html  
Content-Length: 172  
Connection: close

400 Bad Request
# 400 Bad Request

* * *
nginx/1.8.1

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 6:56pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/4 "2016-03-04T18:56:51Z")

</div>

On Friday 04 March 2016 17:41:42 Giulio L. wrote:

> 2016/03/04 15:49:02 [notice] 8991#0: start worker process 8993

[..]

You have another error\_log directive on the “http” level of your  
configuration,  
and it overrides log settings set on the main config level.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 9:48pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/5 "2016-03-04T21:48:00Z")

</div>

## You have been told to use the info error\_log level, which is not set (defaults to error). ​Make sure no other error\_log directive might overwrite this one.​

_B. R._

On Fri, Mar 4, 2016 at 7:12 PM, Giulio L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 7:13pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/6 "2016-03-04T19:13:12Z")

</div>

Still having no luck.  
No log is generated.

TCP connection has any relation to web socket support configuration ?

this is my site config.

server {  
listen 80;  
server\_name [myhost.com](http://myhost.com);  
access\_log /var/log/nginx/myhost.com.log combined;  
error\_log /var/log/nginx/myhost.com.error.log;

```
    root /home/spark/myhost.com/web;
    try_files $uri /index.php;

    set $cache_uri $request_uri;
    if ($request_method = POST) {
            set $cache_uri 'null cache';
    }
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;

            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;

```
             # WebSocket support — not working
             #proxy_pass http://127.0.0.1:8765;
             #proxy_redirect off;
             #proxy_http_version 1.1;
             #proxy_set_header Upgrade $http_upgrade;
             #proxy_set_header Connection "upgrade";
             #proxy_buffering off;

  #debug requests
             #echo_duplicate 1 $echo_client_request_headers;
             #echo "\r";
             #echo_read_request_body;
             #echo $request_body;
    }

```

}

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 11:24pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/7 "2016-03-04T23:24:59Z")

</div>

On Friday 04 March 2016 19:12:56 Giulio L. wrote:

> ```
> access_log /var/log/nginx/myhost.com.log combined;
> error_log /var/log/nginx/myhost.com.error.log;
> 
> ```

[..]

You have another error\_log directive on the “server” level  
that overrides the directives from previous levels.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 11:26pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/8 "2016-03-04T23:26:09Z")

</div>

Here is my nginx.conf and site config.  
After calling tcp connection and getting http 400, no log is generated.

I’m following

Thanks

server {  
listen 80;  
server\_name apidvc.sparkgo.cc;  
access\_log /var/log/nginx/myhost.com.access.log combined;

```
    root /home/spark/myhost.com/web;
    try_files $uri /index.php;

    set $cache_uri $request_uri;
    if ($request_method = POST) {
            set $cache_uri 'null cache';
    }
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in 

```

php.ini

```
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;

```
#debug request
             #echo_duplicate 1 $echo_client_request_headers;
             #echo "\r";
             #echo_read_request_body;
             #echo $request_body;
    }

```

}

The file exists and it is fed as you can see below when I restart nginx:

root@vps190138:~# cat /var/log/nginx-error.log  
2016/03/04 21:14:55 [notice] 13900#0: signal 3 (SIGQUIT) received,  
shutting down  
2016/03/04 21:14:55 [notice] 13902#0: gracefully shutting down  
2016/03/04 21:14:55 [notice] 13902#0: exiting  
2016/03/04 21:14:55 [notice] 13902#0: exit  
2016/03/04 21:14:55 [notice] 13900#0: signal 15 (SIGTERM) received,  
exiting  
2016/03/04 21:14:55 [notice] 13902#0: signal 15 (SIGTERM) received,  
exiting  
2016/03/04 21:14:55 [notice] 13900#0: signal 17 (SIGCHLD) received  
2016/03/04 21:14:55 [notice] 13900#0: worker process 13902 exited with  
code 0  
2016/03/04 21:14:55 [notice] 13900#0: exit  
2016/03/04 21:14:55 [notice] 13949#0: using the “epoll” event method  
2016/03/04 21:14:55 [notice] 13949#0: nginx/1.8.1  
2016/03/04 21:14:55 [notice] 13949#0: OS: Linux 3.13.0-66-generic  
2016/03/04 21:14:55 [notice] 13949#0: getrlimit(RLIMIT\_NOFILE):  
1024:4096  
2016/03/04 21:14:55 [notice] 13950#0: start worker processes  
2016/03/04 21:14:55 [notice] 13950#0: start worker process 13952  
root@vps190138:~#

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 4, 2016, 10:49pm UTC](https://www.ruby-forum.com/t/tcp-connection/244203/9 "2016-03-04T22:49:20Z")

</div>

does /var/log/nginx exist, and it is writeable by the web server user?

On 03/05/2016 07:12 AM, Giulio L. wrote:

> ```
> access_log /var/log/nginx/myhost.com.log combined;
> try_files $uri =404;
> #proxy_redirect off;
> }
> 
> ```
> 
> > > root@vps190138:~# cat /var/log/nginx-error.log  
> > > and it overrides log settings set on the main config level.  
> > > [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Steve H. BSc(Hons) MIITP

> **[Linux & Admin Support Services | "Services provided by people who are proud...](https://www.greengecko.co.nz/)**
>
> Offers linux support services, systems and database administration, consultancy and the full development lifecycle for open source - based solutions

Linkedin: [Steve Holdoway - Robotron New Zealand Limited | LinkedIn](http://www.linkedin.com/in/steveholdoway)  
Skype: sholdowa

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 5, 2016, 12:20am UTC](https://www.ruby-forum.com/t/tcp-connection/244203/10 "2016-03-05T00:20:28Z")

</div>

On Friday 04 March 2016 23:25:27 Giulio L. wrote:

> ```
> access_log /var/log/nginx/myhost.com.access.log combined;
> fastcgi_split_path_info ^(.+\.php)(/.+)$;
> # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
> 
> # With php5-fpm:
> fastcgi_pass unix:/var/run/php5-fpm.sock;
> fastcgi_index index.php;
> include fastcgi_params;
> fastcgi_param SCRIPT_FILENAME
> 
> ```

$document\_root$fastcgi\_script\_name;

> The file exists and it is fed as you can see below when I restart nginx:
> 
> root@vps190138:~# cat /var/log/nginx-error.log  
> 2016/03/04 21:14:55 [notice] 13900#0: signal 3 (SIGQUIT) received, shutting  
> down  
> 2016/03/04 21:14:55 [notice] 13902#0: gracefully shutting down  
> 2016/03/04 21:14:55 [notice] 13902#0: exiting  
> 2016/03/04 21:14:55 [notice] 13902#0: exit  
> 2016/03/04 21:14:55 [notice] 13900#0: signal 15 (SIGTERM) received, exiting  
> 2016/03/04 21:14:55 [notice] 13902#0: signal 15 (SIGTERM) received, exiting  
> 2016/03/04 21:14:55 [notice] 13900#0: signal 17 (SIGCHLD) received  
> 2016/03/04 21:14:55 [notice] 13900#0: worker process 13902 exited with code  
> 0  
> 2016/03/04 21:14:55 [notice] 13900#0: exit  
> 2016/03/04 21:14:55 [notice] 13949#0: using the “epoll” event method  
> 2016/03/04 21:14:55 [notice] 13949#0: nginx/1.8.1  
> 2016/03/04 21:14:55 [notice] 13949#0: OS: Linux 3.13.0-66-generic  
> 2016/03/04 21:14:55 [notice] 13949#0: getrlimit(RLIMIT\_NOFILE): 1024:4096  
> 2016/03/04 21:14:55 [notice] 13950#0: start worker processes  
> 2016/03/04 21:14:55 [notice] 13950#0: start worker process 13952  
> root@vps190138:~#

Do you have other configuration files in your /etc/nginx/conf.d/ and  
/etc/nginx/sites-enabled/ directories, which are included in your  
nginx.conf?

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Giulio\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/0ea827/32.png) [@Giulio\_L](https://www.ruby-forum.com/u/Giulio_L)\
**Post date:** [March 5, 2016, 7:02am UTC](https://www.ruby-forum.com/t/tcp-connection/244203/11 "2016-03-05T07:02:22Z")

</div>

Giulio,

On 3/5/16 1:25 AM, Giulio L. wrote:

> Here is my nginx.conf and site config. After calling tcp  
> connection and getting http 400, no log is generated.
> 
> Im following

Let me re-phrase: this is not your _full_ nginx config. There are  
probably other files in /etc/nginx or somewhere in your system that  
include the snippet below and/or other files. We know that because  
nginx just won’t start with the snippet below for a number of reasons.

To diagnose the issue and provide advises we need full nginx  
configuration. If your nginx version (see nginx -V) is more or less  
recent, i.e 1.9.2+, please run “nginx -T” command to collect the  
configuration. Otherwise just find a folder with the nginx configs  
and check for another error\_log directives (e.g. grep -r error\_log  
/etc/nginx/).

Hope this helps,

Maxim

–  
Maxim K.
