Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run couple of freebsd jails for my web server and application server, which is running node.js

I have one network card (igb0) with a custom loopback interface (lo666) for which i have created 3 aliases, here is part of my /etc/rc.conf

ifconfig_igb0="inet netmask broadcast"
# Custom loopback interface
ifconfig_lo666_alias0="inet netmask"
ifconfig_lo666_alias1="inet netmask"
ifconfig_lo666_alias2="inet netmask"
# Default router

on my /etc/pf.conf i have this

### Interfaces ###
 ExtIf ="igb0"
 IntIf ="lo666"

### Hosts ###
 IP_PUB =""
 IP_JAIL = "{,,}"
 ### Ports ###

scrub in all

# nat all jail traffic
nat pass on $ExtIf from $NET_JAIL to any -> $IP_PUB
rdr pass on $ExtIf proto tcp from any to $IP_PUB port $PORT_WWW -> $IP_JAIL_WWW
rdr pass on $IntIf proto tcp from any to $IP_JAIL_WWW port $PORT_NODE -> $IP_JAIL_APP

so running

# pfctl -sn
nat pass on igb0 inet from to any ->
rdr pass on igb0 inet proto tcp from any to port = http ->
rdr pass on igb0 inet proto tcp from any to port = https ->
rdr pass on lo666 inet proto tcp from any to port = 1337 ->
rdr pass on lo666 inet proto tcp from any to port = 8080 ->

so from the the WWW jail i can

root@www:/ # curl
Hello World

and also from the APP jail i can see the nginx home page

root@app:/# curl
<!DOCTYPE html>
<title>Welcome to nginx!</title>

so, why do i get a 502 Bad Gateway, error when i try to access this through the browser? here is my nginx.conf

server {
      server_name  web.domain.tld;
        location / {
                # For Read Requests
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

this is what i get in my nginx error log

2014/05/23 13:14:44 [error] 92876#0: *1 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream, client:, server: web.domain.tld, request: "GET /favicon.ico HTTP/1.1", upstream: "", host: "web.domain.tld"

maybe i am overcomplicating it and what i wanted to achieve is to block port 1337 to external users.

any advice much appreciated.

share|improve this question

it should be not in the nginx.conf

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.