Mac下安装Nginx及使用
短信预约 -IT技能 免费直播动态提醒
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: openssl@1.1 ✔, 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
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341