Port binding & n8n ? SO_REUSEADDR and SO_REUSEPORT?

Hi there,
Thank you for this amazing tool.

I’ve been trying to install n8n on droplets that has nginx and apache2 running as webservers and of course it was no success due to the conflict over port usage.
And this was already stated by @jan in many occasions.

ERROR: for traefik  Cannot start service traefik: driver failed programming external connectivity on endpoint n8n_traefik_1 (b1584b6959e6e9ecbd6a7d38bdbbd): Error starting userland proxy: listen tcp4 0.0.0.0:443: bind: address already in use
ERROR: Encountered errors while bringing up the project.

After conducting some research around, i’ve learned about SO_REUSEADDR and SO_REUSEPORT : options that allows listening server though previously established ports, even if it’s still being used. Specially SO_REUSEPORT that allows full duplicated bundling,

So my question is ; how can SO_REUSEADDR and SO_REUSEPORT options help solving this problematic ?

Thank you

I have sadly not the slightest idea. Have never heard about that but have honestly also absolutly no experience
Anyway, generally however confused about how that would work. Is like if you and your neighbor have the same mailbox. That you end up with your mail and your neighbor with his, there has to be somebody who checks what letter should go to whom. I wonder what would do that, if two applications are able to share the same port. Normally you would use a reverse proxy to do that job (so set something up like nginx, apache, traefik, …).

Looking at the error the issue is more of a Traefik issue than an n8n one.

I would do (and did) what Jan suggested and remove traefik and use either Apache or Nginx as a reverse proxy for n8n.

Another option would be to change the port that is redirected to the container on the host OS so use something like 4443 instead or if you have multiple IPs bind to the one IP instead of all.

1 Like

@jan @Jon I see, Thank you for your reply.

I tried to use nginx instead of traefik, but no sucess. i’ve never used traefik , And the server has also plesk.
I’m gonna retry and see although i have no experience with Traefik before n8n.

I also changed the port on apache2 but i could not get SSL certificate into it as it is not listning on port 80.

image

@Jon In order to achieve this the correct way do i need to change on the docker compose yml file instead of the of Traefik lines ?

web:
  image: nginx
  volumes:
   - ./templates:/etc/nginx/templates
  ports:
   - "8080:80"
  environment:
   - NGINX_HOST=foobar.com
   - NGINX_PORT=80

Instead of :
image

Then add a WebHook Url in the .env file :

WEBHOOK_URL=foobar.com

Thank you for your help.

I have my nginx running on my host rather than a container but you would want to something like…

version: '3'
services:
  web:
    image: nginx
    ports:
      - 443:443
    volumes:
      - ./site.conf:/etc/nginx/conf.d/site.conf
      - ./certs:/etc/nginx/certs

Then you can set up your config for your reverse proxy or expose the sites-available folder. For Lets Encrypt you can run it on the host and use the DNS method over HTTP although if you wanted to expose port 80 to allow that you could.

Having Plesk or similar on the same server makes it a bit tricky as it will be using the same ports as well which is why in my environment I have nginx on the host as a reverse proxy and for the containers ports they all bind on 127.0.0.1:XXXX where XXXX is a different port I then use the server_name field in my nginx config to route to the correct container with the proxy_pass option.

2 Likes

Thank you so much. A life saver :grinning:
I’m gonna put it to test on my server.

2 Likes