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
--HEAD
        Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The 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/www

The 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
--HEAD
        Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The 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 nginx
  501 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安装验证完毕。

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

《Pytorch深度学习和图神经网络(卷 1)》学习笔记——第七章

这一章内容有点丰富,多用了一些时间,实例就有四五个。 这章内容是真多啊!(学完之后又回到开头感叹) 大脑分级处理机制: 将图像从基础像素到局部信息再到整体信息 即将图片由低级特征到高级特征进行逐级计…

基于群组实现从 Azure AD 到极狐GitLab 的单点登录

目录 配置单点登录 在 Azure AD 中创建企业应用 SAML 基础配置 配置 Azure “Attributes & Claims” 配置用户同步 在极狐GitLab 创建 SCIM Token 配置 Azure Provisioning Azure 手动用户预配 测试单点登录 Azure 自动用户同步 配置群组同步 配置 SAML 群组链…

打jar包

pom文件指定打包的类型是jar&#xff0c;并指定启动主类 <packaging>jar</packaging><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>…

什么条件下会出现死锁,如何避免?

文章目录 一、什么是死锁二、产生死锁的原因&#xff1a;三、如何避免死锁&#xff1a; 一、什么是死锁 死锁&#xff0c;简单来说就是两个或者两个以上的线程在执行过程中&#xff0c;去争夺同一个共享资源导致相互等待的现象。如果没有外部干预&#xff0c;线程会一直处于阻塞…

uniapp封装门票等票务样式

先看效果图 ticketpage组件引用后&#xff0c;根据父级背景颜色改变镂空的颜色,空组件只有中间镂空的样式&#xff0c;上面是插槽heaer,下面内容是插槽content&#xff0c;可以自定义自己的内容和样式。我实现的最终效果是用的uview组件&#xff0c;如果复现需要项目引入。可…

Nginx负载均衡与动静分离

一、Nginx负载均衡&#xff1a; 1.概述&#xff1a; Nginx是一款http服务器软件&#xff0c;支持高达50000个并发连接数的响应。 &#xff08;1&#xff09;拥有强大的处理静态资源的能力。 &#xff08;2&#xff09;运行稳定。 &#xff08;3&#xff09;CPU&#xff0c…

【Unity3D编辑器开发】Unity3D中初次尝试使用PropertyDrawer属性

推荐阅读 CSDN主页GitHub开源地址Unity3D插件分享简书地址我的个人博客 大家好&#xff0c;我是佛系工程师☆恬静的小魔龙☆&#xff0c;不定时更新Unity开发技巧&#xff0c;觉得有用记得一键三连哦。 一、前言 前段时间一直比较忙&#xff0c;没有时间更新博客&#xff0c;…

2011年全国硕士研究生入学统一考试管理类专业学位联考逻辑试题——纯享题目版

&#x1f3e0;个人主页&#xff1a;fo安方的博客✨ &#x1f482;个人简历&#xff1a;大家好&#xff0c;我是fo安方&#xff0c;考取过HCIE Cloud Computing、CCIE Security、CISP、RHCE、CCNP RS、PEST 3等证书。&#x1f433; &#x1f495;兴趣爱好&#xff1a;b站天天刷&…

tomcat接入skywalking

tomcat接入skywalking 一、说明二、步骤2.1 准备java-agent包2.2 tomcat部署2.2.1 下载2.2.2 tomcat修改catalina.sh文件2.2.3 tomcat修改启动端口2.2.4 启动tomcat 三、验证四、问题排查4.1 tomcat的启动日志 一、说明 服务器中已经运行着skywalking&#xff0c;准备在同一台…

7-WebApis-5

Web APIs - 5 目标&#xff1a; 能够利用JS操作浏览器,具备利用本地存储实现学生就业表的能力 BOM操作综合案例 js组成 JavaScript的组成 ECMAScript: 规定了js基础语法核心知识。比如&#xff1a;变量、分支语句、循环语句、对象等等 Web APIs : DOM 文档对象模型&#xff…

2023全云在线联合微软AIGC专场沙龙:人工智能与企业创新,促进创造力的数字化转型

6月29日&#xff0c;由全云在线平台和微软联合主办的人工智能与企业创新&#xff1a;促进创造力的数字化转型——2023AIGC微软专场沙龙在广州天河区正佳万豪酒店举行。 关于2023AIGC微软专场沙龙 GPT翻开了AGI新的一页&#xff0c;也翻开了各行各业的新篇章。 2022年11月30日…

使用Jmeter读取和使用Redis数据

目录 前言 缓存 Redis服务和客户端安装 Jmeter使用Redis 前言 在使用 JMeter 进行性能测试时&#xff0c;有时需要读取和使用 Redis 数据。Redis 是一个开源的内存数据存储系统&#xff0c;常用于缓存、消息队列和数据存储等场景。 缓存 Web系统通常使用数据库来存储数据…

性能测试讲解超详细Jmeter

目录 什么是性能 性能测试的目的 功能测试和性能测试 基准测试 负载测试 稳定性测试 压力测试 并发测试 总结 性能测试指标 响应时间 并发数 吞吐量 点击数 错误率 资源使用率 总结 性能测试流程 性能测试需求分析 性能测试计划和方案 ​编辑性能测试用例​编辑 性…

【MySQL】MySQL数据库,RDBMS 术语,使用说明和报错解决的详细讲解

作者简介&#xff1a; 辭七七&#xff0c;目前大一&#xff0c;正在学习C/C&#xff0c;Java&#xff0c;Python等 作者主页&#xff1a; 七七的个人主页 文章收录专栏&#xff1a; 七七的闲谈 欢迎大家点赞 &#x1f44d; 收藏 ⭐ 加关注哦&#xff01;&#x1f496;&#x1f…

CommonJS 和 ES6 module

本文主要自己觉得要记录的点记录下来,不耽误大家时间&#xff0c;会持续更新。 Module对象 Module {id: xxx/demo/1.js, //加载文件的绝对路径path: xxx/demo,// 加载文件所在目录的绝对路径exports: [Function (anonymous)],filename: xxx/demo/1.js,加载文件的绝对路径load…

蓝桥杯专题-试题版-【圆的面积】【字符串对比】【字母图形】【核桃的数量】

点击跳转专栏>Unity3D特效百例点击跳转专栏>案例项目实战源码点击跳转专栏>游戏脚本-辅助自动化点击跳转专栏>Android控件全解手册点击跳转专栏>Scratch编程案例点击跳转>软考全系列点击跳转>蓝桥系列 &#x1f449;关于作者 专注于Android/Unity和各种游…

Lesson1-1:OpenCV简介

图像处理 学习目标 了解图像的起源知道数字图像的表示 1 图像的起源 1.1 图像是什么 图像是人类视觉的基础&#xff0c;是自然景物的客观反映&#xff0c;是人类认识世界和人类本身的重要源泉。“图”是物体反射或透射光的分布&#xff0c;“像“是人的视觉系统所接受的图在…

【数据库】MySQL 高级(进阶) SQL 语句

文章目录 前提条件一、常用查询1. SELECT&#xff08;显示查询&#xff09;2. DISTINCT&#xff08;不重复查询&#xff09;3. WHERE&#xff08;有条件查询&#xff09;4. AND/OR&#xff08;且/或&#xff09;5. IN &#xff08;显示已知值的字段&#xff09;6. BETWEEN&…

【探索 Kubernetes|作业管理篇 系列 14】StatefulSet 存储状态

前言 大家好&#xff0c;我是秋意零。 在上一篇中&#xff0c;我们讲解了 StatefulSet 的拓扑状态&#xff1b;我们发现&#xff0c;它的拓扑状态&#xff0c;就是顺序启动/删除、Pod 名称编号命名、将 Pod 名称设为 Hostname 名称、通过 Service 无头服务的 DNS 记录访问。 …

4通道AD采集子卡模块有哪些推荐?

FMC134是一款4通道3.2GSPS&#xff08;2通道6.4GSPS&#xff09;采样率12位AD采集FMC子卡模块&#xff0c;该板卡为FMC标准&#xff0c;符合VITA57.4规范&#xff0c;可以作为一个理想的IO模块耦合至FPGA前端&#xff0c;16通道的JESD204B接口通过FMC连接器连接至FPGA的高速串行…