Repository: jupyterhub/jupyterhub

Issue:
Proxy error while non root
I've just installed jupyterhub and tested it successfully running it as root.
However, following the non-root procedure end up on a proxy error after being logged in:

```
rhea@pcjlaforet-cr:/etc/jupyterhub$  jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
[I 2015-03-03 17:41:32.475 JupyterHub app:506] Loading cookie_secret from /etc/jupyterhub/jupyterhub_cookie_secret
[W 2015-03-03 17:41:32.504 JupyterHub app:242] 
    Generating CONFIGPROXY_AUTH_TOKEN. Restarting the Hub will require restarting the proxy.
    Set CONFIGPROXY_AUTH_TOKEN env or JupyterHub.proxy_auth_token config to avoid this message.

[I 2015-03-03 17:41:32.511 JupyterHub app:599] Not using whitelist. Any authenticated user will be allowed.
[I 2015-03-03 17:41:32.523 JupyterHub app:731] Starting proxy @ http://*:8000/
17:41:32.633 - info: [ConfigProxy] Proxying http://*:8000 to http://localhost:8081
17:41:32.635 - info: [ConfigProxy] Proxy API at http://localhost:8001/api/routes
[I 2015-03-03 17:41:42.694 JupyterHub web:1825] 302 GET / (127.0.0.1) 1.45ms
[I 2015-03-03 17:41:42.700 JupyterHub web:1825] 302 GET /hub (127.0.0.1) 0.34ms
[I 2015-03-03 17:41:42.710 JupyterHub web:1825] 302 GET /hub/ (127.0.0.1) 5.91ms
[I 2015-03-03 17:41:42.747 JupyterHub web:1825] 200 GET /hub/home (127.0.0.1) 33.46ms
[I 2015-03-03 17:41:42.906 JupyterHub web:1825] 200 GET /hub/static/js/home.js?v=(%2720150303174132%27,) (127.0.0.1) 5.62ms
[I 2015-03-03 17:41:42.917 JupyterHub web:1825] 200 GET /hub/static/components/jquery/jquery.min.js?v=(%2720150303174132%27,) (127.0.0.1) 2.20ms
[I 2015-03-03 17:41:42.919 JupyterHub web:1825] 200 GET /hub/static/js/jhapi.js?v=(%2720150303174132%27,) (127.0.0.1) 0.70ms
[I 2015-03-03 17:41:42.961 JupyterHub web:1825] 200 GET /hub/static/js/utils.js?v=(%2720150303174132%27,) (127.0.0.1) 0.88ms
[I 150303 17:41:45 mediator:62] Spawning /usr/bin/python3 -m jupyterhub.singleuser --user=jlaforet --port=46992 --cookie-name=jupyter-hub-token-jlaforet --base-url=/user/jlaforet --hub-prefix=/hub/ --hub-api-url=http://localhost:8081/hub/api --ip=localhost
[I 2015-03-03 17:41:45.929 JupyterHub base:209] User jlaforet server took 0.893 seconds to start
[I 2015-03-03 17:41:45.929 JupyterHub orm:154] Adding user jlaforet to proxy /user/jlaforet => http://*:46992
[I 2015-03-03 17:41:45.939 JupyterHub web:1825] 302 GET /hub/user/jlaforet/ (127.0.0.1) 908.02ms
17:41:46.086 - error: [ConfigProxy] Proxy error:  code=ENOTFOUND, errno=ENOTFOUND, syscall=getaddrinfo
```

Feels like there's something misconfigured for the proxy, but i have no clue what.



Discussion:
Can you run it again with:

```
--debug --JupyterHub.debug_db=True
```

?

I'm experiencing the same issue after following the instructions for [Using sudo to run JupyterHub without root privileges](https://github.com/jupyter/jupyterhub/wiki/Using-sudo-to-run-JupyterHub-without-root-privileges). It works fine as a single-user running as root via sudo. 

After starting the server and navigating the front page it displays correctly. The login works, making it to the "My Server" green button.  Clicking this however produces the proxy error: the resulting page has the message `Proxy target missing`

```
http://<ip-address>:8000/hub/home      [...click green button...]
http://<ip-address>:8000/user/mfitzp/    Proxy target missing
```

Alongside the displayed message is the similar output to @jere19 described above.

```
[I 2015-03-04 17:38:51.370 JupyterHub web:1825] 302 GET /hub/user/mfitzp/ (<ip-address>) 565.94ms
17:38:51.380 - error: [ConfigProxy] Proxy error:  code=ENOTFOUND, errno=ENOTFOUND, syscall=getaddrinfo
```

Running the server with `--debug --JupyterHub.debug_db=True` produces the following output. I've trimmed it for the highlighted lines and information regarding proxy/users (removing the SQL debug from SQLAlchemy - happy to provide if it will be helpful).

```
Connecting to db: sqlite:///jupyterhub.sqlite
[W 2015-03-04 17:41:26.368 JupyterHub app:242]
Generating CONFIGPROXY_AUTH_TOKEN. Restarting the Hub will require restarting the proxy.
Set CONFIGPROXY_AUTH_TOKEN env or JupyterHub.proxy_auth_token config to avoid this message.
[I 2015-03-04 17:41:26.376 JupyterHub app:599] Not using whitelist. Any authenticated user will be allowed.

[D 2015-03-04 17:41:26.379 JupyterHub app:671] Loaded users:
 jupyter admin
  mfitzp

[I 2015-03-04 17:41:26.392 JupyterHub app:731] Starting proxy @ http://*:8000/
[D 2015-03-04 17:41:26.392 JupyterHub app:732] Proxy cmd: ['configurable-http-proxy', '--ip', '', '--port', '8000', '--api-ip', 'localhost', '--api-port', '8001', '--default-target', 'http://localhost:8081']

17:41:26.500 - info: [ConfigProxy] Proxying http://*:8000 to http://localhost:8081
17:41:26.503 - info: [ConfigProxy] Proxy API at http://localhost:8001/api/routes

[D 2015-03-04 17:41:26.609 JupyterHub app:752] Proxy started and appears to be up

[D 2015-03-04 17:43:28.456 JupyterHub utils:73] Server at http://localhost:53906/user/mfitzp responded with 302
[I 2015-03-04 17:43:28.457 JupyterHub base:209] User mfitzp server took 1.689 seconds to start
[I 2015-03-04 17:43:28.457 JupyterHub orm:154] Adding user mfitzp to proxy /user/mfitzp => http://*:53906

[D 2015-03-04 17:43:28.460 JupyterHub orm:141] Fetching POST http://localhost:8001/api/routes/user/mfitzp

[I 2015-03-04 17:43:28.472 JupyterHub web:1825] 302 GET /hub/user/mfitzp/ (<ip-address>) 1715.60ms
17:43:28.767 - error: [ConfigProxy] Proxy error:  code=ENOTFOUND, errno=ENOTFOUND, syscall=getaddrinfo
```

I'm running with today's master from Github.

Thanks, I'll see if I can pin down what's wrong.


Resolving patch:
diff --git a/jupyterhub/orm.py b/jupyterhub/orm.py
--- a/jupyterhub/orm.py
+++ b/jupyterhub/orm.py
@@ -77,7 +77,7 @@ def __repr__(self):
     def host(self):
         return "{proto}://{ip}:{port}".format(
             proto=self.proto,
-            ip=self.ip or '*',
+            ip=self.ip or 'localhost',
             port=self.port,
         )
     
@@ -92,7 +92,7 @@ def url(self):
     def wait_up(self, timeout=10, http=False):
         """Wait for this server to come up"""
         if http:
-            yield wait_for_http_server(self.url.replace('//*', '//localhost'), timeout=timeout)
+            yield wait_for_http_server(self.url, timeout=timeout)
         else:
             yield wait_for_server(self.ip or 'localhost', self.port, timeout=timeout)
     


Test patch:
diff --git a/jupyterhub/tests/test_orm.py b/jupyterhub/tests/test_orm.py
--- a/jupyterhub/tests/test_orm.py
+++ b/jupyterhub/tests/test_orm.py
@@ -19,7 +19,11 @@ def test_server(db):
     assert server.proto == 'http'
     assert isinstance(server.port, int)
     assert isinstance(server.cookie_name, str)
-    assert server.url == 'http://*:%i/' % server.port
+    assert server.host == 'http://localhost:%i' % server.port
+    assert server.url == server.host + '/'
+    server.ip = '127.0.0.1'
+    assert server.host == 'http://127.0.0.1:%i' % server.port
+    assert server.url == server.host + '/'
 
 
 def test_proxy(db):