Search code examples
dockernginx

Problem starting ngnix server, error 400 how can I solve it?


I run the command docker run -p 8080:80 nginx for port 80 to be used on my machine as 8080, I get the normal response:

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
c1dfc7e1671e: Download complete
85c41ebe6d66: Download complete
8f28d06e2e2e: Download complete
6f837de2f887: Download complete
578acb154839: Download complete
e398db710407: Download complete
7170a263b582: Download complete
Digest: sha256:86e53c4c16a6a276b204b0fd3a8143d86547c967dc8258b3d47c3a21bb68d3c6
Status: Downloaded newer image for nginx:latest
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/11/14 17:38:19 [notice] 1#1: using the "epoll" event method
2023/11/14 17:38:19 [notice] 1#1: nginx/1.25.3
2023/11/14 17:38:19 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2023/11/14 17:38:19 [notice] 1#1: OS: Linux 5.15.133.1-microsoft-standard-WSL2
2023/11/14 17:38:19 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/11/14 17:38:19 [notice] 1#1: start worker processes
2023/11/14 17:38:19 [notice] 1#1: start worker process 29
2023/11/14 17:38:19 [notice] 1#1: start worker process 30
2023/11/14 17:38:19 [notice] 1#1: start worker process 31
2023/11/14 17:38:19 [notice] 1#1: start worker process 32
2023/11/14 17:38:19 [notice] 1#1: start worker process 33
2023/11/14 17:38:19 [notice] 1#1: start worker process 34
2023/11/14 17:38:19 [notice] 1#1: start worker process 35
2023/11/14 17:38:19 [notice] 1#1: start worker process 36

but when I go to the browser and make a request I get the error:

172.17.0.1 - - [14/Nov/2023:17:38:58 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03I" 400 157 "-" "-" "-"
172.17.0.1 - - [14/Nov/2023:17:38:58 +0000] "\x16\x03\x01\x02L\x01\x00\x02H\x03\x03\xFDe\x80?\xD4\xC1\xEC4t\xF6\x8F\xB8\xD8\x9E\xDFu\x9A 2r\xC2d\x01l." 400 157 "-" "-" "-"
172.17.0.1 - - [14/Nov/2023:17:38:58 +0000] "\x16\x03\x01\x02,\x01\x00\x02(\x03\x03W\xA5\x8C\xD8\x88UJ\x85\xB1\xC1]\x04]P\x1D\xEFV\x88\xC1\x8ALh\xF3\xFBI\xA4+\x8B\x8B)\xA5\xF6 \xBAW\xD9\x12\xE67X\x80\x13\xE6c\xEAa\xA2\x94V\x89\xA6\x06`\x02*/\xC3Hd\x22!\x5CaK|\x00 ZZ\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x01\x00\x01\xBFzz\x00\x00\x00\x10\x00\x0E\x00\x0C\x02h2\x08http/1.1\x00\x0B\x00\x02\x01\x00\x00\x00\x00\x0E\x00\x0C\x00\x00\x09localhost\x00\x05\x00\x05\x01\x00\x00\x00\x00\x00-\x00\x02\x01\x01\x003\x00+\x00)\xAA\xAA\x00\x01\x00\x00\x1D\x00 \xF4\x22\xE8\xB2\x80J\x17\xCA\x82k\xB7\x9Aj\xF4\x86w\xFCpn6\xAEA\xD1\x02\xA4\xD7\x99n\xE4\xD0/S\x00+\x00\x07\x06zz\x03\x04\x03\x03\xFE" 400 157 "-" "-" "-"

I tried to upload an nginx server


Solution

  • Your nginx container is getting error because you are trying to use https for the nginx server which is listening to http host port 8080 (mapped to container port 80). https won't work since you haven't configured ssl and thus giving this error.

    To solve this, use http:// instead of https:// in the URL, like following:

    http://127.0.0.1:8080
    

    Following is the log for http (working case):

    172.17.0.1 - - [14/Nov/2023:19:05:57 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" "-"
    

    Also, below I have attached full logs when I reproduced the issue on my machine:

    172.17.0.1 - - [14/Nov/2023:18:56:50 +0000] "\x16\x03\x01\x07\x12\x01\x00\x07\x0E\x03\x03\x0El\xAAz\xABBz\x90\x84<>\x82\x0Br\x15\xEB\xDD\x80\xC9KC\x93B\xDC\xDF\x00\xB2\xD0\xBA\x06\xBA\xBA J*\xD9\xD9\xC8\xAA9\x89\xA7-\xB5L\xFC\xAC\xC7\xD6\x96\x9D>z\x8Be\xFB\xD9o\xBCeH\xAF\xC7\x1E\xD5\x00 \xFA\xFA\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x01\x00\x06\xA5JJ\x00\x00\x00" 400 157 "-" "-" "-"
    172.17.0.1 - - [14/Nov/2023:18:56:50 +0000] "\x16\x03\x01\x06\xD2\x01\x00\x06\xCE\x03\x03\xA3\x90t\xF9\x07\xA3\x05\xF1\xAC\xA8\x94\xF4\xC6.\xD9\x13\x00\xABME%\xEB\x14W\xBEm\xC8\xFC\x1D\xD83\x81 1,\xC8\x9FIlI\x90\xF2h\x8C=8\xC1Y\xE1\x96P\x9A\x93\x11\xD3\xDF\x84Kp\xEA\x973\xA8\x93\xE1\x00 \xAA\xAA\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x01\x00\x06ejj\x00\x00\x00\x17\x00\x00\x00\x1B\x00\x03\x02\x00\x02\x00\x05\x00\x05\x01\x00\x00\x00\x00\x00\x00\x00\x0E\x00\x0C\x00\x00\x09localhost\x00" 400 157 "-" "-" "-"
    172.17.0.1 - - [14/Nov/2023:18:56:50 +0000] "\x16\x03\x01\x06\xD2\x01\x00\x06\xCE\x03\x03\x11$jD\x17/.\xB8\x97\xD0\x94\x11\xA2\x9AE\x99\xBE\x84u\xBBZ\xA4\xB8\x94A\x96\x13\xD4\xD4H6\x13 \xFAk\xF74\x89O]\xF8s.\xF6\xB3G(\x1A\x1D!Ry\xBFN\xAFR\xA0=\xE1\xA5\x94\x15ife\x00 ::\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x01\x00\x06e\xCA\xCA\x00\x00\x00#\x00\x00\x00\x05\x00\x05\x01\x00\x00\x00\x00\xFE" 400 157 "-" "-" "-"
    172.17.0.1 - - [14/Nov/2023:18:56:50 +0000] "\x16\x03\x01\x06\xB2\x01\x00\x06\xAE\x03\x03\x08\xB6\x0C\x80\xFD\x07\xAB\xE9?!\xB9X\xF8H\x9A\xB8rg\x89\xC9\x195\xE0\xAF\xF2\x12\xCC\x96\xFE\xDC\xB8\xF3 c\x9C\xD2\x16\x1D\x8B\xA8\x09\x96>w\x11\xDE\x93\xB5\x93\xA3j\x17\x9B\xB2\x7F\x02\xA0\xD5~\xA5\x5Cx\xD7\x9E\xD6\x00 JJ\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x01\x00\x06E**\x00\x00\x00" 400 157 "-" "-" "-"