一、安裝 Nginx
- 終端執行:
brew search nginx brew install nginx
當前版本 1.10.2,通過brew可以把nginx需要的pcre,openssl,zlib全部一鍵裝好。
安裝完以后,可以在終端輸出的信息里看到一些配置路徑:
/usr/local/etc/nginx/nginx.conf (配置文件路徑) /usr/local/var/www (服務器默認路徑) /usr/local/Cellar/nginx/1.10.2_1 (安裝路徑)
執行nginx -V可以看到安裝配置過程的一些選項,能自動化安裝,就不要手動安裝,不然會有各種出乎意料的問題。
nginx version: nginx/1.10.2 built by clang 8.0.0 (clang-800.0.38) built with OpenSSL 1.1.0b 26 Sep 2016 TLS SNI support enabled configure arguments: --prefix=/usr/local/Cellar/nginx/1.10.2_1 --with-http_ssl_module --with-pcre --sbin-path=/usr/local/Cellar/nginx/1.10.2_1/bin/nginx --with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl@1.1/include' --with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl@1.1/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module --with-ipv6
可以通過執行ps -ef | grep nginx快速查看nginx master進程的pid,通過kill來關閉,通過執行nginx -c /user/local/etc/nginx/nginx.conf來重新打開
二、訪問localhost:8080
Nginx 默認8080端口,這時已經可以訪問了:
localhost:8080
會有一個默認歡迎界面。