I am trying to configure nginx proxy for a tcp service, the http proxy stuff works as expected. However, I keep getting this error for the server inside the stream context.
no handler for server in /etc/nginx/nginx.conf:6
I don't understand how it's different from the servers defined in the http context.
events {
}
stream {
server {
listen 5601;
deny all;
}
}
http {
server {
listen 80;
server_name example.com;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
return 301 https://$host$request_uri;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
proxy_pass http://example.com:5601;
}
}
}
What does this error mean and how do I fix this?
The problem lies here:
listen 5601;
deny all;
The listen dont understand, what will I am to do for listen here?
Immediately it found a deny all;. what will I am doing with deny?.
So you must tell the listen to what to do it stand for. For ex:
listen 853;
proxy_pass 127.0.0.1:53;
Here, I ordered listen to do something. So it know what to do it stand for. It was there to listen on port 853 and then proxying to localhost. Ya, somethink like that.
Dont forget to restart
sudo systemctl restart nginx.services
You said:
I don't understand how it's different from the servers defined in the http context.
Sure. Because server on http know what to do after listen. :)