(base) ➜ brew info nginx nginx: stable 1.21.3 (bottled), HEAD HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server https://nginx.org/ /opt/homebrew/Cellar/nginx/1.21.3 (26 files, 2.2MB) * Poured from bottle on 2022-06-16 at 17:13:49 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb License: BSD-2-Clause ==> Dependencies Required: openssl@1.1 ✔, pcre ✔ ==> Options --HEAD Install HEAD version ==> Caveats Docroot is: /opt/homebrew/var/www
The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.
nginx will load all files in /opt/homebrew/etc/nginx/servers/.
To restart nginx after an upgrade: brew services restart nginx Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/nginx/bin/nginx -g daemon off; ==> Analytics install: 38,896 (30 days), 91,488 (90 days), 455,183 (365 days) install-on-request: 38,823 (30 days), 91,297 (90 days), 454,267 (365 days) build-error: 48 (30 days)
1 2 3
The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. 这行我们可以了解到默认nginx配置文件是/opt/homebrew/etc/nginx/nginx.conf
// ProxyRequestHandler handles the http request using proxy funcProxyRequestHandler(proxy *httputil.ReverseProxy)func(http.ResponseWriter, *http.Request) { returnfunc(w http.ResponseWriter, r *http.Request) { proxy.ServeHTTP(w, r) } }
funcmain() { // initialize a reverse proxy and pass the actual backend server url here proxy, err := NewProxy("http://localhost:3000") //proxy, err := NewProxy("http://localhost:3000") if err != nil { panic(err) }
// handle all requests to your server using the proxy http.HandleFunc("/", ProxyRequestHandler(proxy)) log.Fatal(http.ListenAndServe(":8888", nil)) }