Nginx是一款高性能的Web服务器和反向代理服务器,可以处理高并发的请求。
1、在Mac上安装
安装Homebrew:如未安装Homebrew, 在终端中输入以下命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1.1、 安装Nginx:在终端中输入以下命令:
brew install nginx
Mac Homebrew 卸载nignx
brew uninstall nginx
安装过程日志
Last login: Fri Oct 20 08:23:17 on console
*@MACdeMacBook-Pro ~ % brew install nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.19.6.catalina.bottl
##O=# #
curl: (60) SSL: no alternative certificate subject name matches target host name 'homebrew.bintray.com'
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
Error: Failed to download resource "nginx"
Download failed: https://homebrew.bintray.com/bottles/nginx-1.19.6.catalina.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading https://nginx.org/download/nginx-1.19.6.tar.gz
######################################################################## 100.0%
==> tar -cJf /usr/local/Cellar/nginx/1.19.6/share/nginx/src/src.tar.xz --options
==> ./configure --prefix=/usr/local/Cellar/nginx/1.19.6 --sbin-path=/usr/local/C
==> make install
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Summary
🍺 /usr/local/Cellar/nginx/1.19.6: 10 files, 2.1MB, built in 1 minute 8 seconds
*@MACdeMacBook-Pro ~ %
1.2、查看Nginx安装的版本
*@MACdeMacBook-Pro ~ % nginx -V
nginx version: nginx/1.19.6
built by clang 12.0.0 (clang-1200.0.32.29)
built with OpenSSL 1.1.1i 8 Dec 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.19.6 --sbin-path=/usr/local/Cellar/nginx/1.19.6/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-compat --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-ipv6 --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
*@MACdeMacBook-Pro ~ %
1.3、查看Nginx信息
*@MACdeMacBook-Pro ~ % brew info nginx
# nginx安装版本
nginx: stable 1.19.6 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.6 (10 files, 2.1MB) *
Built from source on 2023-10-20 at 08:58:54
#下载地址
From: git://mirrors.ustc.edu.cn/homebrew-core.git/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1 ✔, pcre ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
#nginx 默认静态文件位置
Docroot is: /usr/local/var/www
#nginx.conf配置文件位置
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
#nginx 服务目录
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
# 使用这个命令未能成功启动nginx,使用的是 sudo nginx
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Analytics
install: 10,446 (30 days), 43,155 (90 days), 118,717 (365 days)
install-on-request: 10,425 (30 days), 43,068 (90 days), 118,525 (365 days)
build-error: 7 (30 days)
1.4、 启动Nginx:在终端中输入以下命令:
sudo nginx
或
nginx
或
brew services start nginx
1.5. 停止Nginx:在终端中输入以下命令:
sudo nginx -s stop
或
brew services stop nginx
1.6、重新加载Nginx配置文件:在终端中输入以下命令:
sudo nginx -s reload
或
nginx -s reload
或
brew services restart nginx
1.7、查看Nginx进程:在终端中输入以下命令:
ps -ef | grep nginx
1.8、nginx在本机实际使用的相关命令:
# 开启
sudo nginx
# 关闭
sudo nginx -s stop
# 重启
sudo nginx -s reload
1.9、配置文件位置:
可以使用文本编辑器进行编辑nginx.conf文件,根据实际需求增改配置:
/usr/local/etc/nginx/nginx.conf
参考: