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

在这里插入图片描述

相关文章
|
2天前
|
编解码 Java 程序员
写代码还有专业的编程显示器?
写代码已经十个年头了, 一直都是习惯直接用一台Mac电脑写代码 偶尔接一个显示器, 但是可能因为公司配的显示器不怎么样, 还要接转接头 搞得桌面杂乱无章,分辨率也低,感觉屏幕还是Mac自带的看着舒服
|
4天前
|
存储 缓存 关系型数据库
MySQL事务日志-Redo Log工作原理分析
事务的隔离性和原子性分别通过锁和事务日志实现,而持久性则依赖于事务日志中的`Redo Log`。在MySQL中,`Redo Log`确保已提交事务的数据能持久保存,即使系统崩溃也能通过重做日志恢复数据。其工作原理是记录数据在内存中的更改,待事务提交时写入磁盘。此外,`Redo Log`采用简单的物理日志格式和高效的顺序IO,确保快速提交。通过不同的落盘策略,可在性能和安全性之间做出权衡。
1540 5
|
1月前
|
弹性计算 人工智能 架构师
阿里云携手Altair共拓云上工业仿真新机遇
2024年9月12日,「2024 Altair 技术大会杭州站」成功召开,阿里云弹性计算产品运营与生态负责人何川,与Altair中国技术总监赵阳在会上联合发布了最新的“云上CAE一体机”。
阿里云携手Altair共拓云上工业仿真新机遇
|
7天前
|
人工智能 Rust Java
10月更文挑战赛火热启动,坚持热爱坚持创作!
开发者社区10月更文挑战,寻找热爱技术内容创作的你,欢迎来创作!
582 22
|
4天前
|
存储 SQL 关系型数据库
彻底搞懂InnoDB的MVCC多版本并发控制
本文详细介绍了InnoDB存储引擎中的两种并发控制方法:MVCC(多版本并发控制)和LBCC(基于锁的并发控制)。MVCC通过记录版本信息和使用快照读取机制,实现了高并发下的读写操作,而LBCC则通过加锁机制控制并发访问。文章深入探讨了MVCC的工作原理,包括插入、删除、修改流程及查询过程中的快照读取机制。通过多个案例演示了不同隔离级别下MVCC的具体表现,并解释了事务ID的分配和管理方式。最后,对比了四种隔离级别的性能特点,帮助读者理解如何根据具体需求选择合适的隔离级别以优化数据库性能。
201 3
|
10天前
|
JSON 自然语言处理 数据管理
阿里云百炼产品月刊【2024年9月】
阿里云百炼产品月刊【2024年9月】,涵盖本月产品和功能发布、活动,应用实践等内容,帮助您快速了解阿里云百炼产品的最新动态。
阿里云百炼产品月刊【2024年9月】
|
11天前
|
Linux 虚拟化 开发者
一键将CentOs的yum源更换为国内阿里yum源
一键将CentOs的yum源更换为国内阿里yum源
580 5
|
23天前
|
存储 关系型数据库 分布式数据库
GraphRAG:基于PolarDB+通义千问+LangChain的知识图谱+大模型最佳实践
本文介绍了如何使用PolarDB、通义千问和LangChain搭建GraphRAG系统,结合知识图谱和向量检索提升问答质量。通过实例展示了单独使用向量检索和图检索的局限性,并通过图+向量联合搜索增强了问答准确性。PolarDB支持AGE图引擎和pgvector插件,实现图数据和向量数据的统一存储与检索,提升了RAG系统的性能和效果。
|
7天前
|
XML 安全 Java
【Maven】依赖管理,Maven仓库,Maven核心功能
【Maven】依赖管理,Maven仓库,Maven核心功能
235 3
|
9天前
|
存储 人工智能 搜索推荐
数据治理,是时候打破刻板印象了
瓴羊智能数据建设与治理产品Datapin全面升级,可演进扩展的数据架构体系为企业数据治理预留发展空间,推出敏捷版用以解决企业数据量不大但需构建数据的场景问题,基于大模型打造的DataAgent更是为企业用好数据资产提供了便利。
327 2