Mac os 安装 nginx 教程(success)

简介: 这篇文章是关于如何在Mac OS系统上使用Homebrew安装nginx及其依赖,并解决安装过程中可能出现的权限问题。

前言

  1. 最近使用Mac系统,从新预习一下nginx,所以写了这篇博客,以便以后和广大好友减少麻烦。
  2. 安装启动完会发现,在Mac下安装nginx,和Linux下安装nginx,其实没有区别。就是先安装三个依赖包,最后安装nginx即可。唯一的区别可能是三个依赖包的安装方式不同罢了。
  3. 注意下最后的bug,很简单,手动创建文件夹即可,原因是因为没有权限创建文件夹而已~

一、homebrew

1、介绍

Mac下包管理工具:homebrew

2、下载安装

安装开始的截图,接着跟着流程执行即可
在这里插入图片描述

二、安装nginx

1、安装前准备

nginx 依赖于 pcre、zlib、openssl

  1. nginx的http模块使用pcre来解析正则表达式,需要在linux上安装pcre
  2. nginx使用zlib对http包的内容进行gzip,需要在linux上安装安装zlib
  3. 安装openssl库,让 nginx 支持 https(即在ssl协议上传输http)

缺少依赖会报错如下错误

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

a、安装pcre

  1. 执行命令 brew install pcre
  2. 命令执行如下:
    在这里插入图片描述

    (base) C02ZT6HWLVDL:nginx-1.22.1 alsc$ brew install pcre
    Running `brew update --auto-update`...
    ==> Homebrew has enabled anonymous aggregate formula and cask analytics.
    Read the analytics documentation (and how to opt-out) here:
      https://docs.brew.sh/Analytics
    No analytics have been recorded yet (nor will be during this `brew` run).
    
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    
    ==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/pcre-8.45.big_sur.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring pcre-8.45.big_sur.bottle.tar.gz
    🍺  /usr/local/Cellar/pcre/8.45: 204 files, 5.8MB
    ==> Running `brew cleanup pcre`...
    Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    

b、安装zlib

  1. 执行命令 brew install zlib
  2. 命令执行如下:
    在这里插入图片描述

    (base) C02ZT6HWLVDL:nginx-1.22.1 alsc$ brew install zlib
    ==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/zlib-1.2.13.big_sur.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring zlib-1.2.13.big_sur.bottle.tar.gz
    ==> Caveats
    zlib is keg-only, which means it was not symlinked into /usr/local,
    because macOS already provides this software and installing another version in
    parallel can cause all kinds of trouble.
    
    For compilers to find zlib you may need to set:
      export LDFLAGS="-L/usr/local/opt/zlib/lib"
      export CPPFLAGS="-I/usr/local/opt/zlib/include"
    
    ==> Summary
    🍺  /usr/local/Cellar/zlib/1.2.13: 13 files, 424.9KB
    ==> Running `brew cleanup zlib`...
    Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    

c、安装openssl

  1. 执行命令 brew install openssl

  2. 命令执行如下:
    在这里插入图片描述
    在这里插入图片描述

    (base) C02ZT6HWLVDL:nginx-1.22.1 alsc$ brew install openssl
    ==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/ca-certificates-2022-10-11.all.bottle.tar
    ######################################################################## 100.0%
    ==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/openssl%403-3.0.7.big_sur.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Installing dependencies for openssl@3: ca-certificates
    ==> Installing openssl@3 dependency: ca-certificates
    ==> Pouring ca-certificates-2022-10-11.all.bottle.tar.gz
    ==> Regenerating CA certificate bundle from keychain, this may take a while...
    🍺  /usr/local/Cellar/ca-certificates/2022-10-11: 3 files, 225.4KB
    ==> Installing openssl@3
    ==> Pouring openssl@3-3.0.7.big_sur.bottle.tar.gz
    ==> Caveats
    A CA file has been bootstrapped using certificates from the system
    keychain. To add additional certificates, place .pem files in
      /usr/local/etc/openssl@3/certs
    
    and run
      /usr/local/opt/openssl@3/bin/c_rehash
    
    openssl@3 is keg-only, which means it was not symlinked into /usr/local,
    because macOS provides LibreSSL.
    
    If you need to have openssl@3 first in your PATH, run:
      echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/alsc/.bash_profile
    
    For compilers to find openssl@3 you may need to set:
      export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
      export CPPFLAGS="-I/usr/local/opt/openssl@3/include"
    
    ==> Summary
    🍺  /usr/local/Cellar/openssl@3/3.0.7: 6,454 files, 28.4MB
    ==> Running `brew cleanup openssl@3`...
    Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    ==> Caveats
    ==> openssl@3
    A CA file has been bootstrapped using certificates from the system
    keychain. To add additional certificates, place .pem files in
      /usr/local/etc/openssl@3/certs
    
    and run
      /usr/local/opt/openssl@3/bin/c_rehash
    
    openssl@3 is keg-only, which means it was not symlinked into /usr/local,
    because macOS provides LibreSSL.
    
    If you need to have openssl@3 first in your PATH, run:
      echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> /Users/alsc/.bash_profile
    
    For compilers to find openssl@3 you may need to set:
      export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
      export CPPFLAGS="-I/usr/local/opt/openssl@3/include"
    

2、下载nginx

官网:http://nginx.org/
在这里插入图片描述
在这里插入图片描述

3、安装

  1. 我这里下载的是1.22.1的包,将你下载的 nginx-1.22.1.tar.gz 放在你想放的路径,
  2. 解压:tar -zxvf nginx-1.22.1.tar.gz
  3. 编译:sudo ./configuresudo是 super user do 的简称,使用管理员执行命令,主要是为辅助超级管理员完成一些超级管理员不能登录下的操作
  4. 安装:sudo make && make install
  5. 安装完成

4、 安装的异常:Permission denied

最后执行流程截图,发现异常:
在这里插入图片描述

/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile install
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
mkdir: /usr/local/nginx: Permission denied
make[1]: *** [install] Error 1
make: *** [install] Error 2
(base) C02ZT6HWLVDL:nginx-1.22.1 alsc$ ls

意思应该是创建文件夹没有权限,导致make install错误,安装错误。
所以手动创建,并改权限即可

sudo mkdir -p /usr/local/nginx
sudo chmod -R 777 /usr/local/nginx
sudo make && make install

执行完安装命令,则显示如下,无报错信息,能发现 /usr/local/nginx/ 已经有了数据,则success
在这里插入图片描述
然后:

cd /usr/local/nginx/sbin
./nginx

输入地址 http://localhost:80 看到如图内容,即nginx部署成功
补充说明:每次启动会麻烦可以建立全局变量
方案一:ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
方案二:
vi /etc/profile
export NGINX_HOME=/usr/local/nginx
export PATH= P A T H :NGINX_HOME/sbin
source /etc/profile
配置后启动:
nginx

在这里插入图片描述

相关文章
|
5月前
|
应用服务中间件 网络安全 nginx
手把手教你使用 Docker 部署 Nginx 教程
本文详解Nginx核心功能与Docker部署优势,涵盖镜像拉取、容器化部署(快速、挂载、Compose)、HTTPS配置及常见问题处理,助力高效搭建稳定Web服务。
2437 4
|
6月前
|
前端开发 安全 测试技术
Postman Mac 版安装终极指南:从下载到流畅运行,一步到位
Postman 是 API 开发与测试的高效工具,支持各类 HTTP 请求调试与团队协作。本文详解 Mac 版下载、安装步骤,助你快速上手。同时推荐一体化 API 协作平台 Apifox,集文档、调试、测试于一体,提升开发效率与团队协同能力。
|
7月前
|
Ubuntu 物联网 Linux
从零安装一个Linux操作系统几种方法,以Ubuntu18.04为例
一切就绪后,我们就可以安装操作系统了。当系统通过优盘引导起来之后,我们就可以看到跟虚拟机中一样的安装向导了。之后,大家按照虚拟机中的顺序安装即可。 好了,今天主要介绍了Ubuntu Server版操作系统的安装过程,关于如何使用该操作系统,及操作系统更深层的原理,还请关注本号及相关圈子。
|
10月前
|
Ubuntu 网络协议 应用服务中间件
在 Ubuntu 上安装 Nginx
在 Ubuntu 上安装和配置 Nginx 非常简单。首先更新系统包,然后通过 `apt` 安装 Nginx,检查服务状态并配置防火墙规则。访问服务器 IP 测试是否成功显示默认页面。还可管理服务、创建虚拟主机及排查常见问题,适合新手快速上手部署高性能 Web 服务。
1266 0
|
10月前
|
安全 Linux 数据安全/隐私保护
安装RHEL9.x操作系统
本教程详细介绍了在Windows系统上使用VMware Workstation 17.5 Pro安装RHEL 9.x的完整流程。首先准备所需设备和软件,包括Windows计算机、RHEL 9 ISO映像文件、VMware软件及相关下载链接。接着,通过创建虚拟机、配置硬件参数完成VMware的基本设置。随后进入RHEL 9.x安装环节,涵盖语言选择、软件配置、网络和主机名设置、时区调整、磁盘分区规划(如/boot、/、swap、/boot/efi等分区)以及用户和密码的创建。最后,启动安装程序并监控进度,直至系统重启进入图形化登录界面。整个过程配有详细步骤说明和截图,便于用户操作和理解。
安装RHEL9.x操作系统
|
7月前
|
Web App开发 Ubuntu Oracle
Ubuntu安装与使用详解:掌握开源操作系统的钥匙
遵循这些步骤和指南,你将能够顺利地开始使用Ubuntu,并充分利用其强大的功能和友好的界面。
|
7月前
|
安全 Ubuntu Linux
如何安装Linux操作系统?
此时,您可以选择重新启动计算机,然后从硬盘上的Linux系统启动。以上是一个大致的安装过程。请注意,不同的Linux发行版可能会在细节上有所差异,因此在进行安装之前,请确保您阅读并理解了相应发行版的安装指南或文档。
|
7月前
|
Ubuntu Unix Linux
玩机强化技能,动手安装Ubuntu Linux操作系统
(13)Ubuntu重启过程中,你将在关机画面中看到提示文字“Please remove the installation medium, then press ENTER:”,按下“Enter”键即可重启电脑。
|
7月前
|
Ubuntu 开发工具
Ubuntu 22.04 aarch64版本操作系统下编译ZLMediaKit教程
通过上述步骤,你可以在Ubuntu 22.04 aarch64版本上成功编译ZLMediaKit,这是一个相对简单而直接的过程,但可能会遇到一些需要根据具体系统环境和要求调整的地方。
1005 0
|
9月前
|
iOS开发 MacOS 索引
在不受支持的 Mac 上安装 macOS Tahoe 26
在不受支持的 Mac 上安装 macOS Tahoe 26
756 0
在不受支持的 Mac 上安装 macOS Tahoe 26

热门文章

最新文章

推荐镜像

更多