Nginx listens at a port, only responds if set to port 80
Try the following server block:
server {
listen 81 default_server;
server_name _;
root /usr/share/nginx/html;
location / {
index index.html;
}
}
The underscore _
is a wildcard, Also the *:81
likely doesn't do what you expect, just use the port number.
Then test your settings with nginx -t
:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart nginx:
service nginx restart
Test with netstat:
root@gitlab:~# netstat -napl | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7903/nginx
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 2662/unicorn.
Update
I installed nginx on a test system. With the stock nginx.conf
file and a 1 line change to /etc/nginx/sites-enabled/default
, I was able to retrieve files from port 81
cat /etc/nginx/sites-enabled/default
server {
listen 81;
server_name localhost;
root /usr/share/nginx/www;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
Netstat output:
netstat -napl | grep 81
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 3432/nginx
Download file:
$ wget localhost:81
Contents of file:
$ cat index.html
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
Update2
Test port:
root@gitlab:# nc -vz localhost 81
Connection to localhost 81 port [tcp/*] succeeded!
root@gitlab:# nc -vz localhost 443
nc: connect to localhost port 443 (tcp) failed: Connection refused
Turns out the big problem? Nginx had set worker_processes to 0. I added a line setting it to auto
in the top of my nginx.conf, and all was well with the world!
Thank you all for your time and patience.