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

news2024/9/20 22:54:46

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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

网络规划工具

对于各种规模的企业和组织来说,应对安全威胁和可靠的网络性能至关重要。战略性地投资有效的网络监控解决方案可以节省时间和成本,减少停机时间并提高员工的生产力,还可以让管理员专注于重要的事情。重要的是要了解,随着业务的增长…

JAVA大作业——网络在线对战游戏——坦克大战

目录 大作业要求 实机演示 主机环回地址布置连接演示 多人联机对战演示 WASD控制坦克移动和按J键发射炮弹攻击 攻击到敌人后会爆炸并且消灭敌人 按下C键设置IP主机连接 大作业要求 简单的小游戏 要求1:能够实现例如贪吃蛇、坦克大战、俄罗斯方块等小游戏&#x…

红帽:多云和AI时代,开放混合云是最优选择

随着云计算市场群雄割据的格局逐渐定型,混合多云的环境已经成为大势所趋。而近年来AI人工智能技术的高速发展,则进一步为技术创新注入了澎湃动力。 那么问题就来了:在这个多云和AI大行其道的时代,企业应该选择什么样的云平台&…

删除PDF页面的10个操作工具方法分享

PDF被广泛用于各种目的,包括共享学术文件、专业报告,甚至个人文件。然而,有时您可能会发现需要从PDF中删除一些页面。虽然有很多付费软件可供选择,但也有很多免费删除PDF页面的方法。在这篇文章中,我们将讨论10种免费删…

这所广东的985录取平均分387分,复录比高达3.5,单科线55分!

一、学校及专业介绍 中山大学(Sun Yat-sen University),简称“中大”,位于广东省,位列国家“双一流”、“985工程”、“211工程”,学校由广州、珠海、深圳三个校区,博士后科研流动站44个&#x…

CentOS7安装部署OpenVidu

1:安装Docker 参考:Centos7 安装 Docker_zzhongcy的博客-CSDN博客 2:安装OpenVidu 2.1、OpenVidu 简介 OpenVidu Server(openvidu-server):是openvidu平台的大脑,负责信号层。Kurento Media Server(kms)…

软件测试技能,JMeter压力测试教程,批量注册测试账号(计数器的使用)(十二)

一、前言 当我们jmeter压测的时候,需要准备一批测试账号,可以先批量注册一些用户,这些用户名称按固定格式 注册的用户不能重复并且需要自增,那么可以使用计数器来实现 二、添加注册请求 我想批量注册100个账号,账号…

【uniapp微信小程序footer】不满一屏固定显示在底部,超出一屏随页面滚动

<template><view class"wrapper"><view class"main">...</view><view class"footer">xx智慧农场</view></view > </template> <style>page {height: 100%;}.wrapper {height: 100%;}.ma…

高德地图的使用

JS API 结合 Vue 使用 高德地图 jsapi 下载、引入 npm add amap/amap-jsapi-loaderimport AMapLoader from amap/amap-jsapi-loader 使用2.0版本的loader需要在window对象下先配置 securityJsCode JS API 安全密钥使用 JS API 使用 script 标签同步加载增加代理服务器设置…

不定长(可变) 位置参数 *args和关键字参数 **kwargs 详解

位置参数&#xff1a; 传参时前面不带 "变量名", 顺序不可变, 按顺序赋给相应的局部变量def test(one,two,three):print(one - two * three)test(1,2,3) def test(one,two,three):print(one - two * three)test(3,2,1) 注意位置参数&#xff0c;需要注意 1 、 不…

STM32外设系列—BH1750

文章目录 一、BH1750简介二、BH1750原理图三、BH1750数据手册3.1 指令集3.2 IIC通信读/写 四、BH1750程序设计4.1 IIC程序4.2 BH1750初始化程序4.3 读取BH1750测量结果4.4 获取光照强度4.5 相关宏定义 五、应用实例六、拓展应用6.1 实时调节LED亮度6.2 实时调整颜色阈值 一、BH…

【Flutter】 Flutter 状态管理 BLoC 简明使用指南

文章目录 一、前言二、Flutter BLoC 的安装和配置三、Flutter BLoC 的基本使用四、Flutter BLoC 的简单示例五、总结 一、前言 &#x1f389;想要精通 Flutter&#xff0c;掌握更多技巧和最佳实践&#xff1f;好消息来了&#xff01;&#x1f449; Flutter专栏->Flutter De…

波动率预言机:开启新的DeFi风险管理策略和衍生市场

Chainlink 喂价一直是 DeFi 生态系统的基础构建块&#xff0c;为越来越多的加密货币、大宗商品和法定货币提供准确、防篡改和聚合的价格参考数据。高质量的价格数据的可用性在 DeFi 的增长过程中起到了重要作用&#xff0c;使其总锁定资产价值在高峰期达到了 1700 亿美元&#…

基于云计算技术B/S架构的医院信息管理系统源码(HIS)

云HIS系统源码&#xff0c;采用云端SaaS服务的方式提供 基于云计算技术的B/S架构的云HIS系统&#xff0c;采用云端SaaS服务的方式提供&#xff0c;使用用户通过浏览器即能访问&#xff0c;无需关注系统的部署、维护、升级等问题&#xff0c;系统充分考虑了模板化、配置化、智能…

MySQL基础之概述

MySQL 启动、终止 //以管理员身份运行cmd net start mysql80 net stop mysql80客户端连接 客户端cmd “开始”找到MySQL 环境变量普通cmd mysql [-h 127.0.0.1] [-P 3306] -u root -p mysql -u root -p[ ] 内的参数可省略&#xff0c;若连接本地MySQL&#xff0c;则无需指定…

机器学习笔记 - 结合深度学习的基于内容的图像实例检索 利用现成的DCNN模型进行检索

一、简述 上一篇,基于内容的图像实例检索综述。 https://mp.csdn.net/mp_blog/creation/editor/131415155https://mp.csdn.net/mp_blog/creation/editor/131415155 一种方案是,为分类任务而进行大规模训练的DCNN直接充当图像检索任务的现成特征检测器,也就是说,可以…

Live800:为什么越来越多的企业选择在线客服系统?

现今&#xff0c;越来越多的企业开始使用在线客服系统&#xff0c;这是因为互联网时代已经席卷全球&#xff0c;企业需要尽可能地利用新技术&#xff0c;优化客户体验和服务。一个强大的在线客服系统可以帮助企业实现客服信息的统一管理&#xff0c;这样可以为企业带来巨大的好…

Vue Router 相关理解 基本路由 多级路由

6.1.相关理解 6.1.1.vue-router 的理解 vue的一个插件库&#xff0c;专门用来实现SPA应用 6.1.2.对SPA应用的理解 单页Web应用&#xff08;single page web application&#xff0c;SPA&#xff09;整个应用只有一个完整的页面点击页面中的导航链接不会刷新页面&#xff0c…

Find My资讯|苹果Find My技术应用于车内丢失设备

美国专利商标局正式授予苹果两项泰坦项目新专利&#xff0c;分别是扩展其针对车内丢失设备的“Find My”设备服务&#xff0c;以及用于自动驾驶汽车的高级传感器系统&#xff0c;其中传感器系统还涵盖了带有摄像头系统的车辆&#xff0c;而摄像头系统除可3D重建场景之外&#x…

通过网络流量监测分析解决堡垒主机部署后未经授权访问的3389端口问题

1. 前言 堡垒主机是网络安全的重要组成部分&#xff0c;但在部署后仍可能存在一些主机可以绕过堡垒主机直接访问之前的3389端口。本文将介绍如何利用网络流量监测分析方法解决这个问题&#xff0c;提供一种有效的解决方案&#xff0c;加强对网络的访问控制和安全监测。 2. 网…