我已经启动了一个Compojure(Jetty)服务器:
(defonce *server* (run-server {:host "localhost" :port 8080} "/*" (servlet routes)))
但是netstat仍然显示它正在监听0.0.0.0:8080,即所有IP。
传递给run-server以使其在单个IP上侦听的正确参数是什么?
答案 0 :(得分:7)
我认为你将不得不修补Compojure。它没有对您的:host
参数执行任何操作。将此更改改为server/jetty.clj
似乎有效,但我没有对其进行彻底测试。
(defn- create-server "Construct a Jetty Server instance." [options servlets] (let [port (options :port 80) host (options :host "0.0.0.0") connector (doto (org.mortbay.jetty.bio.SocketConnector.) (.setPort port) (.setHost host)) server (doto (Server.) (.addConnector connector)) servlets (partition 2 servlets)] (when (or (options :ssl) (options :ssl-port)) (add-ssl-connector! server options)) (doseq [[url-or-path servlet] servlets] (add-servlet! server url-or-path servlet)) server))
user> (run-server {:port 12346})
2009-07-22 13:48:53.999::INFO: jetty-6.1.15
2009-07-22 13:48:54.002::INFO: Started SocketConnector@0.0.0.0:12346
nil
user> (run-server {:host "127.0.0.1" :port 12345})
2009-07-22 13:48:08.061::INFO: jetty-6.1.15
2009-07-22 13:48:08.129::INFO: Started SocketConnector@127.0.0.1:12345