I'm moving the server side of an IoT application from the 'net (FreeBSD
10.3 and nginx) to a server on my home network (OpenBSD 6.0 and httpd).
The server runs a php script.  The IoT device POSTs an xml file to the
server and the php script processes it.

I set up php on httpd and redirected (using pf) the IoT device to the
server.  Unfortunately, the IoT device acted as if the server were not
seeing the traffic, even though httpd's log file said differently.

Wanting to eliminate a difference, I loaded the nginx pkg onto OpenBSD.
The IoT device works fine using nginx on OpenBSD, but doesn't work using
httpd on OpenBSD.

I also simplified the POST so that it is a simple text string.



Diving into tcpdump, I found an important difference between httpd and
nginx.  Here are the details of the setup, php script and tcpdump info:


server section of httpd.conf:

server "plink.24cl.home" {
        listen on 10.20.1.1 port 8081

        root "/htdocs/plink/data/"

        log style       combined
        log access      plink-access.log
        log error       plink-error.log

        location "/scripts/*.php" {
                fastcgi socket "/run/php-fpm.sock"
        }
}



server section of nginx.conf:

server {
    listen       8080;
    server_name  localhost;
    root         /var/www/htdocs/plink/data;

    location ~ \.php$ {
        try_files      $uri $uri/ =404;
        fastcgi_pass   unix:run/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

(note: the fastcgi_param line wrapped)




Here is what I use to do the POST: (note, they wrapped)

curl -X POST -d "port 8080 - nginx"  http://10.20.1.1:8080/scripts/test.php

curl -X POST -d "port 8081 - httpd"  http://10.20.1.1:8081/scripts/test.php



Here is test.php:

<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
        $data = "this is a test\n";
        $datalen=strlen($data);
        header("Content-type: text/xml");
        header("Content-length: $datalen");
        echo $data;
}
?>



And, finally, here are the tcpdump outputs:


httpd:

11:03:49.907047 10.20.1.1.8081 > 10.20.3.31.52481: P [tcp sum ok]
1:221(220) ack 182 win 2142 <nop,nop,timestamp 3414331483 672822409>
(ttl 64, id 24106, len 272)
  0000: 4500 0110 5e2a 0000 4006 0377 0a14 0101  E...^*..@..w....
  0010: 0a14 031f 1f91 cd01 d665 d72e 2805 7228  .........e..(.r(
  0020: 8018 085e 05b0 0000 0101 080a cb82 905b  ...^...........[
  0030: 281a 7489 4854 5450 2f31 2e31 2032 3030  (.t.HTTP/1.1 200
  0040: 204f 4b0d 0a43 6f6e 6e65 6374 696f 6e3a   OK..Connection:
  0050: 206b 6565 702d 616c 6976 650d 0a43 6f6e   keep-alive..Con
  0060: 7465 6e74 2d74 7970 653a 2074 6578 742f  tent-type: text/
  0070: 786d 6c3b 6368 6172 7365 743d 5554 462d  xml;charset=UTF-
  0080: 380d 0a44 6174 653a 2054 6875 2c20 3133  8..Date: Thu, 13
  0090: 204f 6374 2032 3031 3620 3135 3a30 333a   Oct 2016 15:03:
  00a0: 3439 2047 4d54 0d0a 5365 7276 6572 3a20  49 GMT..Server:
  00b0: 4f70 656e 4253 4420 6874 7470 640d 0a54  OpenBSD httpd..T
  00c0: 7261 6e73 6665 722d 456e 636f 6469 6e67  ransfer-Encoding
  00d0: 3a20 6368 756e 6b65 640d 0a58 2d50 6f77  : chunked..X-Pow
  00e0: 6572 6564 2d42 793a 2050 4850 2f35 2e36  ered-By: PHP/5.6
  00f0: 2e32 330d 0a0d 0a66 0d0a 7468 6973 2069  .23....f..this i
  0100: 7320 6120 7465 7374 0a0d 0a30 0d0a 0d0a  s a test...0....


nginx:

11:04:28.659022 10.20.1.1.8080 > 10.20.3.31.61550: P [tcp sum ok]
1:195(194) ack 182 win 2142 <nop,nop,timestamp 115326800 672861161> (ttl
64, id 25269, len 246)
  0000: 4500 00f6 62b5 0000 4006 ff05 0a14 0101  E...b...@.......
  0010: 0a14 031f 1f90 f06e 83b4 841e 3c15 56b8  .......n....<.V.
  0020: 8018 085e fcaf 0000 0101 080a 06df bf50  ...^...........P
  0030: 281b 0be9 4854 5450 2f31 2e31 2032 3030  (...HTTP/1.1 200
  0040: 204f 4b0d 0a53 6572 7665 723a 206e 6769   OK..Server: ngi
  0050: 6e78 0d0a 4461 7465 3a20 5468 752c 2031  nx..Date: Thu, 1
  0060: 3320 4f63 7420 3230 3136 2031 353a 3034  3 Oct 2016 15:04
  0070: 3a32 3820 474d 540d 0a43 6f6e 7465 6e74  :28 GMT..Content
  0080: 2d54 7970 653a 2074 6578 742f 786d 6c3b  -Type: text/xml;
  0090: 6368 6172 7365 743d 5554 462d 380d 0a43  charset=UTF-8..C
  00a0: 6f6e 7465 6e74 2d4c 656e 6774 683a 2031  ontent-Length: 1
  00b0: 350d 0a43 6f6e 6e65 6374 696f 6e3a 206b  5..Connection: k
  00c0: 6565 702d 616c 6976 650d 0a58 2d50 6f77  eep-alive..X-Pow
  00d0: 6572 6564 2d42 793a 2050 4850 2f35 2e36  ered-By: PHP/5.6
  00e0: 2e32 330d 0a0d 0a74 6869 7320 6973 2061  .23....this is a
  00f0: 2074 6573 740a                            test.




The difference between the two is that httpd does not include the
Content-length header that I specify in the php script, while nginx does.

Is there a way to encourage httpd to include the Content-length header,
or do I need to stay with nginx for this app?

Thanks.

Reply via email to