Nginx | 苹果电脑Mac安装和验证Nginx服务过程记录

common wx:CodingTechWork,一起学习进步。

引言

  本文主要总结如何在Mac电脑上进行Nginx服务的安装,重点讲解使用brew命令进行安装和验证的过程及问题记录。

安装步骤

安装过程记录

查看nginx信息

首先使用命令brew info nginx进行本机nginx的查看。

liaojianya@liaojianyadeMacBook-Pro downloads % brew info nginx                                        
nginx: stable 1.21.6 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
Not installed
From: https://mirrors.ustc.edu.cn/homebrew-core.git/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1 ✔, pcre2 ✘
==> Options
--HEADInstall HEAD version
==> Caveats
Docroot is: /usr/local/var/wwwThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.nginx will load all files in /usr/local/etc/nginx/servers/.To restart nginx after an upgrade:brew services restart nginx
Or, if you don't want/need a background service you can just run:/usr/local/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 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)

可以看到Not installed,需要去安装。

安装nginx

brew install nginx

liaojianya@liaojianyadeMacBook-Pro downloads % brew install nginx                                     
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/pcre2-10.40.big_sur.bottle.tar.gz
##O=#  #                                                                      
curl: (22) The requested URL returned error: 404 
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/pcre2/manifests/10.40
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/6a61595f05721663f0cee49a258476b0c9c9bca499f44f4cb437a1f9cc2e5d2b--pcre2-10.40.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/pcre2/blobs/sha256:0108a261b51c0c8628eb94fb92a00e33867dccac8b6756a71a24e47f596125c7
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/4077ce3d6665d1a9874a4f6f3a9b92df56eb22e861284bbfc3142b0f80cd0d08--pcre2--10.40.big_sur.bottle.tar.gz
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/nginx-1.21.6_1.big_sur.bottle.tar.gz
##O=#  #                                                                      
curl: (22) The requested URL returned error: 404 
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/nginx/manifests/1.21.6_1
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/4fb2767b05e700f1cd175f9f7ac8ce64a15a9f87c8cf8ff9b9897aea93965bce--nginx-1.21.6_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/nginx/blobs/sha256:4b6822266d64a0aa1baea76f01ead5ec163a90311747fa624cf9f234a7ee41b6
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/977e001977161d0a0bdb1d798b4da0b83965b682cc4f8ab412a7bb5ab9d80e29--nginx--1.21.6_1.big_sur.bottle.tar.gz
==> Installing dependencies for nginx: pcre2
==> Installing nginx dependency: pcre2
==> Pouring pcre2-10.40.big_sur.bottle.tar.gz
Error: No such file or directory @ rb_sysopen - /Users/liaojianya/Library/Caches/Homebrew/downloads/de3e1c15aa2f708af57eb6c8309c36b834615fef7fdd35239e69dac0998e32ca--pcre2-10.40.big_sur.bottle.tar.gz

报错信息:Error: No such file or directory @ rb_sysopen - /Users/liaojianya/Library/Caches/Homebrew/downloads/de3e1c15aa2f708af57eb6c8309c36b834615fef7fdd35239e69dac0998e32ca--pcre2-10.40.big_sur.bottle.tar.gz

解决方案:brew install pcre2

liaojianya@liaojianyadeMacBook-Pro downloads % brew install pcre2
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/pcre2-10.40.big_sur.bottle.tar.gz
#=#=-#  #                                                                     
curl: (22) The requested URL returned error: 404 
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/pcre2/manifests/10.40
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/6a61595f05721663f0cee49a258476b0c9c9bca499f44f4cb437a1f9cc2e5d2b--pcre2-10.40.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/pcre2/blobs/sha256:0108a261b51c0c8628eb94fb92a00e33867dccac8b6756a71a24e47f596125c7
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/4077ce3d6665d1a9874a4f6f3a9b92df56eb22e861284bbfc3142b0f80cd0d08--pcre2--10.40.big_sur.bottle.tar.gz
==> Pouring pcre2--10.40.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/pcre2/10.40: 230 files, 6.4MB
==> Running `brew cleanup pcre2`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).


再次安装nginx:brew install nginx

liaojianya@liaojianyadeMacBook-Pro downloads % brew install nginx
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/nginx-1.21.6_1.big_sur.bottle.tar.gz
##O#- #                                                                       
curl: (22) The requested URL returned error: 404 
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/nginx/manifests/1.21.6_1
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/4fb2767b05e700f1cd175f9f7ac8ce64a15a9f87c8cf8ff9b9897aea93965bce--nginx-1.21.6_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/nginx/blobs/sha256:4b6822266d64a0aa1baea76f01ead5ec163a90311747fa624cf9f234a7ee41b6
Already downloaded: /Users/liaojianya/Library/Caches/Homebrew/downloads/977e001977161d0a0bdb1d798b4da0b83965b682cc4f8ab412a7bb5ab9d80e29--nginx--1.21.6_1.big_sur.bottle.tar.gz
==> Pouring nginx--1.21.6_1.big_sur.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/wwwThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.nginx will load all files in /usr/local/etc/nginx/servers/.To restart nginx after an upgrade:brew services restart nginx
Or, if you don't want/need a background service you can just run:/usr/local/opt/nginx/bin/nginx -g daemon off;
==> Summary
🍺  /usr/local/Cellar/nginx/1.21.6_1: 26 files, 2.2MB
==> Running `brew cleanup nginx`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

再次查看nginx信息

brew info nginx

liaojianya@liaojianyadeMacBook-Pro downloads % brew info nginx   
nginx: stable 1.21.6 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.21.6_1 (26 files, 2.2MB) *Poured from bottle on 2023-06-20 at 09:12:22
From: https://mirrors.ustc.edu.cn/homebrew-core.git/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1 ✔, pcre2 ✔
==> Options
--HEADInstall HEAD version
==> Caveats
Docroot is: /usr/local/var/wwwThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.nginx will load all files in /usr/local/etc/nginx/servers/.To restart nginx after an upgrade:brew services restart nginx
Or, if you don't want/need a background service you can just run:/usr/local/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 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)

其中:

  1. 安装目录信息:/usr/local/Cellar/nginx/1.21.6_1 (26 files, 2.2MB) *
  2. 安装来源信息:From: https://mirrors.ustc.edu.cn/homebrew-core.git/Formula/nginx.rb
  3. 根目录信息:Docroot is: /usr/local/var/www
  4. 配置文件信息及默认端口信息:The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.

查看下载文件

liaojianya@liaojianyadeMacBook-Pro downloads % ls
4077ce3d6665d1a9874a4f6f3a9b92df56eb22e861284bbfc3142b0f80cd0d08--pcre2--10.40.big_sur.bottle.tar.gz    6a61595f05721663f0cee49a258476b0c9c9bca499f44f4cb437a1f9cc2e5d2b--pcre2-10.40.bottle_manifest.json
4fb2767b05e700f1cd175f9f7ac8ce64a15a9f87c8cf8ff9b9897aea93965bce--nginx-1.21.6_1.bottle_manifest.json   977e001977161d0a0bdb1d798b4da0b83965b682cc4f8ab412a7bb5ab9d80e29--nginx--1.21.6_1.big_sur.bottle.tar.gz

启动nginx服务

brew services start nginx

liaojianya@liaojianyadeMacBook-Pro downloads % open /usr/local/etc/nginx/
liaojianya@liaojianyadeMacBook-Pro downloads % open /usr/local/Cellar/nginx
liaojianya@liaojianyadeMacBook-Pro downloads % brew services start nginx 
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

验证安装效果

查看nginx进程

ps -ef | grep nginx

liaojianya@liaojianyadeMacBook-Pro nginx % ps -ef | grep nginx501 30392     1   0  9:14AM ??         0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;  501 30395 30392   0  9:14AM ??         0:00.00 nginx: worker process 

访问nginx首页

访问http://localhost:8080地址
访问nginx首页

修改配置文件

  1. 编辑nginx配置文件

    vim nginx.conf
    image.png
    修改端口号为8081
  2. 重启nginx服务

    重启命令:brew services restart nginx
liaojianya@liaojianyadeMacBook-Pro nginx % brew services restart nginx
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx**)**
  1. 再次访问nginx首页

    访问http://localhost:8081地址

image.png

配置静态资源访问

创建图片路径

# 临时创建photo文件夹
liaojianya@liaojianyadeMacBook-Pro ~ % mkdir photo
liaojianya@liaojianyadeMacBook-Pro ~ % cd photo
liaojianya@liaojianyadeMacBook-Pro photo % pwd
/Users/liaojianya/photo
# 拷贝一张图片到该目录下
liaojianya@liaojianyadeMacBook-Pro photo % ls
111.jpeg

修改nginx配置文件

vim nginx.conf,在server块中增加

        location ~* \.(gif|jpg|jpeg|png)$ {root /Users/liaojianya/photo/;}

验证nginx.conf配置文件正确性

使用nginx -t命令

liaojianya@liaojianyadeMacBook-Pro nginx % nginx -t 
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

重启nginx服务

使用命令brew services restart nginx重启

liaojianya@liaojianyadeMacBook-Pro nginx % brew services restart nginx
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

访问静态图片

在浏览器中打开地址:http://localhost:8081/111.jpeg

image.png
至此nginx安装验证完毕。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/2160.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux下Master-Master Replication Manager for MySQL 双主故障切换

简述: Master-Master Replication Manager for MySQL(MMRM)是一种用于MySQL数据库的主-主复制管理工具。它允许在多个MySQL主机之间建立双向的主-主复制关系,实现数据的同步和高可用性。 工作原理是通过在每个MySQL主机上配置双…

传统后端漏洞----(Web Server) 解析漏洞

笔记 前言IIS解析漏洞文件夹解析漏洞原理限制条件 ";" 分号截断漏洞原理 IIS解析漏洞检测IIS 文件夹解析漏洞检测IIS 分号截断漏洞检测 防御手段 Nginx解析漏洞Nginx 文件类型错误解析漏洞导致任意PHP代码执行原理Nginx 空字节解析漏洞导致任意文件可解析&#xff08…

【详细分析】thinkphp反序列化漏洞

文章目录 配置xdebug反序列化漏洞利用链详细分析poc1(任意文件删除)测试pocpoc2(任意命令执行)poc3(任意命令执行) 补充代码基础函数trait关键字应用案例优先级多trait 配置xdebug php.ini [Xdebug] zend…

Spring Boot 中的 WebMvc 是什么,原理,如何使用

Spring Boot 中的 WebMvc 是什么,原理,如何使用 介绍 在 Spring Boot 中,WebMvc 是非常重要的一个模块。它提供了一系列用于处理 Web 请求的组件和工具。在本文中,我们将介绍 Spring Boot 中的 WebMvc 是什么,其原理…

“配置DHCP Snooping实验:保护网络中的DHCP服务和防止欺骗攻击“

"配置DHCP Snooping实验:保护网络中的DHCP服务和防止欺骗攻击" 【实验目的】 部署DHCP服务器。熟悉DHCP Snooping的配置方法。验证拓扑。 【实验拓扑】 实验拓扑如图所示。 设备参数如下表所示。 设备 接口 IP地址 子网掩码 默认网关 R1 F0/0 …

vue element UI在button按钮使用 @keyup.enter不生效

如图所示,没效果。在按钮上绑定keyup事件,加上.native覆盖原有封装的keyup事件 解决办法 created () {document.onkeyup e > {if (e.keyCode 13 && e.target.baseURI.match(/login/)) {// 调用登录 验证方法this.submitForm()}}}成功解决&…

MySQL子查询

😇作者介绍:一个有梦想、有理想、有目标的,且渴望能够学有所成的追梦人。 🎆学习格言:不读书的人,思想就会停止。——狄德罗 ⛪️个人主页:进入博主主页 🗼专栏系列:进入MySQL专栏知…

如何使用upupw搭建服务器,并映射外网访问

作为计算机行业从业人员,相信很多人都接触并使用过phpstudy等类似环境集成包,着对于upupw就比较好理解了。UPUPW绿色服务器平台是Windows下很有特色的一款免费服务器PHP套件,UPUPW PHP套件简化了PHP环境搭建步骤,一个压缩包解压到…

【MOOC 作业】第4章 网络层

不是标答也不是参考答案 仅从个人理解出发去做题 1、(20分) 考虑如图示的网络。 a. 假定网络是一个数据报网络。显示路由器 A 中的转发表,其中所有指向主机 H3 的流量通过接口 3 转发。 目的网络链路接口H33 b. 假定网络是一个数据报网络。你能写出路由器 A 中的…

设计模式篇(Java):单例模式

上一篇:设计模式篇(Java):前言(UML类图、七大原则) 四、单例模式 所谓类的单例设计模式,就是采取一定的方法保证在整个的软件系统中,对某个类只能存在一个对象实例,并且该类只提供一个取得其对象实例的方法(静态方法)…

【Linux系列P5】gccg++与【动静态库】的美妙邂逅

前言 大家好吖,欢迎来到 YY 滴 Linux系列 ,热烈欢迎!本章主要内容面向接触过Linux的老铁,主要内容含 欢迎订阅 YY 滴Linux专栏!更多干货持续更新!以下是传送门! 订阅专栏阅读:YY的《…

快速部署K8s仪表板,助力管理轻松搞定!

https://kubernetes.io/zh-cn/docs/tasks/access-application-cluster/web-ui-dashboard/ Dashboard 是基于网页的 Kubernetes 用户界面。 你可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群资源。 你可以使…