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.
AI 代码解读

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`).
    
    AI 代码解读

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`).
    
    AI 代码解读

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"
    
    AI 代码解读

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
AI 代码解读

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

sudo mkdir -p /usr/local/nginx
sudo chmod -R 777 /usr/local/nginx
sudo make && make install
AI 代码解读

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

cd /usr/local/nginx/sbin
./nginx
AI 代码解读

输入地址 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

在这里插入图片描述

目录
打赏
0
0
0
0
53
分享
相关文章
Debina操作系统如何安装Tengine并开启HTTP2
本指南介绍了Tengine的安装与配置方法。首先下载并解压Tengine源码包,确保依赖项已安装(如pcre、zlib和openssl)。接着运行`./configure`命令进行配置,建议添加`--with-http_v2_module`以启用HTTP/2支持。完成配置后执行`make`编译,再通过`sudo make install`完成安装。为方便使用,可创建符号链接指向Tengine二进制文件。
Debina操作系统如何安装OpenResty并开启HTTP2
本文介绍了在Debian服务器上安装OpenResty 1.25.3.2并启用HTTP/2模块的详细步骤。包括下载解压源码、安装依赖项、配置编译参数(指定安装路径与启用HTTP/2模块)、编译安装,以及创建符号链接方便使用。最后提供启动、停止和重新加载配置的命令,并提醒注意安全组设置以确保服务正常访问。
Debian操作系统如何安装Nginx并开启HTTP2
本指南介绍了在Linux系统中通过源码编译安装Nginx的完整流程。首先更新软件包列表并安装必要的编译依赖,接着下载指定版本的Nginx源码包(如1.24.0),检查文件完整性后解压。随后通过配置脚本指定安装路径与模块(如HTTP SSL模块),执行编译和安装命令。最后创建软链接以便全局调用,并提供启动、停止及重载Nginx的命令,同时提醒注意安全组设置以确保正常访问。
安装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操作系统
os-copilot安装_配置_功能测试全集
我是一位中级运维工程师,我平时工作会涉及到 各类服务器的 数据库 与 java环境配置 操作。 我顺利使用了OS Copilot的 -t -f | 功能,我的疑惑是不能在自动操作过程中直接给与脚本运行权限,必须需要自己运行一下 chmod 这个既然有了最高的权限,为什么就不能直接给与运行权限呢。 我认为 -t 功能有用,能解决后台运行基础命令操作。 我认为 -f 功能有用,可以通过task文件中撰写连续任务操作。 我认为 | 对文件理解上有很直接的解读,可以在理解新程序上有很大帮助。
229 86
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
219 30
YashanDB安装前操作系统参数调整
本文来自YashanDB官网,主要介绍在Linux环境下安装YashanDB时的系统性能优化配置。内容涵盖服务器hostname设置、关闭交换分区、调整本地端口范围、进程VMA上限及资源限制值、配置大页内存与关闭透明大页等操作。通过这些调整,可提升系统运行效率并避免潜在异常,适用于分布式部署场景,同时提供了具体命令和注意事项以指导用户完成配置。
|
4月前
|
Ubuntu gnome WhiteSur-gtk-theme类mac主题正确安装和卸载方式
通过这个过程,用户不仅可以定制自己的桌面外观,还可以学习到更多关于 Linux 系统管理的知识,从而更好地掌握系统配置和主题管理的技巧。
418 12
os-copilot安装与多项功能测评,帮助开发人员PHP环境排查问题
本文介绍了OS Copilot在ECS上 Alibaba Cloud Linux的安装与使用,并对其多项参数进行了功能测评。OS Copilot是为操作系统提供智能化辅助的工具,支持自动化任务、智能推荐、故障排查等功能。安装时需检查是否已安装(`rpm -q os-copilot`),若未安装则用`yum install os-copilot`命令安装,并配置AccessKey信息连接阿里云服务。通过测试不同参数命令,如`-t`参数,展示了其自动化执行和智能生成回答的能力,显著提升运维效率。
os-copilot安装与多项功能测评,帮助开发人员PHP环境排查问题

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问