Mac 安装 Nginx 及配置
- 更新 Homebrew
brew update
- 下载并安装 Nginx
brew install nginx
- 查看 nginx 配置信息
tong@MacBook-Pro ~ % brew info nginx版本信息==> nginx: stable 1.25.1 (bottled), HEADHTTP(S) server and reverse proxy, and IMAP/POP3 proxy serverhttps://nginx.org/Nginx安装目录/opt/homebrew/Cellar/nginx/1.25.1 (26 files, 2.4MB) *Poured from bottle using the formulae.brew.sh API on 2023-06-17 at 15:52:25安装来源From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rbLicense: BSD-2-Clause==> DependenciesRequired: [email protected] ✔, pcre2 ✔==> Options--HEADInstall HEAD version根目录==> CaveatsDocroot is: /opt/homebrew/var/www重点!!!nginx 的配置文件及默认启动端口 8080The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so thatnginx can run without sudo.Nginx将在 Server 目录下加载所有文件,在这个nginx will load all files in /opt/homebrew/etc/nginx/servers/.To start nginx now and restart at login:brew services start nginxOr, if you don't want/need a background service you can just run:/opt/homebrew/opt/nginx/bin/nginx -g daemon off;==> Analyticsinstall: 81,387 (30 days), 151,458 (90 days), 151,458 (365 days)install-on-request: 81,387 (30 days), 151,458 (90 days), 151,458 (365 days)build-error: 0 (30 days)
- Nginx常用命令
启动brew services start nginx停止brew services stop nginx终端进入nginx 目录cd /opt/homebrew/etc/nginx编辑 nginx.conf 配置文件vim nginx.conf 编辑完成后:wq保存退出重新加载配置文件nginx -s reload
- Nginx配置文件nginx.conf
全局配置events { worker_connections 1024;}http { http 配置 #原本没有,自己手动添加 upstream XX{ //负载均衡配置 } #主要配置 server,配自己需要的信息 server { listen 8070; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://localhost:8080; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } //原注释,现在释放生效 # HTTPS server server { listen 443 ssl; server_name localhost; #证书 cert.pen和 cert.key换成证书的目录 ssl_certificate cert.pem; ssl_certificate_key cert.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } } include servers/*;}
配置文件主要是配置 server 里面的内容,需要理解反向代理的概念,在编辑 nginx.conf时建议备份,防止修改错误,注意添加的代码均要是 ; 结尾。
本文转载自: https://blog.csdn.net/Xiao_tongtong/article/details/131300892
版权归原作者 TomYee 所有, 如有侵权,请联系我们删除。
版权归原作者 TomYee 所有, 如有侵权,请联系我们删除。