I’m having an odd problem here. I’m trying to set up nginx with a
varnish
proxy in front of it. The box is Ubuntu 15.10, nginx 1.9.3, varnish
4.0.3.
For testing I set up varnish on port 8080, and nginx was running on port
80
and 443. I shut down both, edit the config files so that varnish is
listening on port 80 and forwarding to the nginx backend on 8080. I do a
search and replace on all the listen directives in
/etc/nginx/sites-enabled
to change listen 80 to listen 8080.
When I restart nginx, it comes up listening on port 8080 and 443 as
expected, but ALSO on port 80. This means varnish is unable to start up
as
the port is already bound.
I’ve checked through the nginx conf files many times. There are no other
listen 80 directives. I’ve also tried putting a server block in the main
nginx.conf with listen 8080 in it, but that doesn’t help.
I think the problem may be that this system is confused between systemd
and
init.d. I was having trouble with varnish in this respect. However I’ve
checked all the systemd files and none of them mention a port, and the
/etc/init.d/nginx file doesn’t either.
Why is nginx using port 80? And how to stop it! Any pointers gratefully
received.
Without showing your nginx config it’s unlikely that anyone will be able
to
troubleshoot. Likely there is a stray listen directive that’s causing
this.
Without showing your nginx config it’s unlikely that anyone will be able
to
troubleshoot. Likely there is a stray listen directive that’s causing
this.
There are no stray listen directives. I’ve checked many times.
grep -ril listen /etc/nginx
Shows only files in sites-enabled and sites-available directories.
grep -i listen /etc/nginx/sites-enabled
Shows only port 8080
grep 80 /etc/nginx/sites-enabled
Shows only port 8080
I’ve also manually opened all files and verified just in case my
grepping
skills were failing. I’ve checked probably 10 times. This is why I can’t
figure it out and came to ask the mailing list!
So, just to be clear, these are the ones running now without varnish. Of
course the lines with listen 80 are changed to listen 8080, and when I
restart nginx, it appears on ports 80, 8080 and 443.
===========
There are three other domains in this directory, all created by copying
and
editing the domain1 file. So nothing extra in there. You’ll just have to
take my word for it that the listen directives are all the same.
On Fri, Apr 01, 2016 at 12:42:57AM -0400, plutocrat wrote:
Hi there,
There are no stray listen directives. I’ve checked many times.
grep -ril listen /etc/nginx
Shows only files in sites-enabled and sites-available directories.
grep -i listen /etc/nginx/sites-enabled
Shows only port 8080
grep 80 /etc/nginx/sites-enabled
Shows only port 8080
“Default” there means that if a server{} block does not have any listen
directive, it is equivalent to “listen *:80” (or “listen *:8080” if
running as non-root).
Your “letsencrypt” server{} block does not have any listen directive.
So add one there – and to any other similar blocks – or do not start
nginx as root (and therefore be unable to listen to any port below
1024).
“Default” there means that if a server{} block does not have any
listen directive, it is equivalent to “listen *:80” (or “listen *:8080”
if
running as non-root).
Your “letsencrypt” server{} block does not have any listen directive.
Oh wow. It was that simple. Thanks. I probably should have found it, but
when you start going around in circles its hard to break out. Adding a
listen directive to the letsencrypt server {} block fixed it.
Posted at Nginx Forum:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.