1. 安装
brew install nginx
  1. 查看 nginx 版本
nginx -v

查看Nginx信息

brew info nginx

  1. 启动 nginx
nginx
  1. 查看 nginx 是否启动成功
    在浏览器中访问http://localhost:8080,如果出现如下界面,则说明启动成功.

  2. 关闭nginx

nginx -s stop

也可以使用下面的命令启动,但是配置文件nginx.conf修改后用这个命令执行不生效,故不建议使用:sudo brew services stop nginx

  1. 重新加载nginx
nginx -s reload
  1. 查看Nginx配置文件
vim /usr/local/etc/nginx/nginx.conf

查看Nginx配置文件的位置以及是否配置成功 nginx -t 命令

8. 为nginx指定一个配置文件

nginx -c filename 为nginx指定一个配置文件

Nginx配置文件内容如下:


#user  nobody;
#-- Nginx占用几个CPU
worker_processes  1; #-- 记录错误日志,默认只记录错误日志,如果想记录警告、信息等内容,可以在后面添加notice、info
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {#-- 每个CPU支持1024个并发。总处理数量:worker_processes * worker_connectionsworker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#-- 自定义打印日志格式#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on; 如果开启gzip,则文件传输会按照chuncked形式传输,并且不会response content-length字段,因为被压缩了,不知道实际大小。server {listen       8080;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}include servers/*;
}

log_format 各个变量值的含义:

log_format main   '$remote_addr - $remote_user [$time_local] ''"$request" $status $bytes_sent ''"$http_j_forwarded_for" "$http_x_forwarded_for" ''"$http_referer" "$http_user_agent" ''"$gzip_ratio"';
  • $remote_addr
  • $remote_user[$time_local]
  • $bytes_sent
  1. 查看nginx安装目录, 如下命令:
open /usr/local/etc/nginx/


总结nginx常见的配置:

nginx的配置文件路径:/usr/local/etc/nginx/nginx.conf
nginx的服务器默认路径:/usr/local/var/www
nginx的安装路径:/usr/local/Cellar/nginx/1.15.5


动静分离:动态资源和静态资源分开。
静态资源:HTML、CSS、JavaScript、图片、音频、视频等


如何启动Nginx缓存:

Nginx启用缓存需要在最顶层的http节点下配置proxy_cache_path命令。
链接:https://www.cnblogs.com/asheng2016/p/proxy_cache.html

proxy_cache_path  /data/nginx/cache  levels=1:2  keys_zone=STATIC_CACHE:10m  inactive=24h  max_size=1g;server {listen 80;proxy_cache       STATIC_CACHE;proxy_cache_valid 200 302 10m;proxy_cache_valid 301      1h;proxy_cache_valid any      1m;proxy_cache_use_stale  error timeout invalid_header updatinghttp_500 http_502 http_503 http_504;location ~* \.(jpg|jpeg|png|gif|bmp|mp4)$ {proxy_pass http://static;include    proxy_params;}
}

参考:https://www.zze.xyz/archives/nginx-proxycache.html
参考:https://www.cnblogs.com/redirect/p/10066766.html#21-proxy_cache_path
参考:https://www.cnblogs.com/asheng2016/p/proxy_cache.html

Mac 安装和使用Nginx教程相关推荐

  1. mac安装WireShark2.0新手教程

    mac安装WireShark2.0新手教程 在你开始之前 此版本的Wireshark需要macOS 10.12或更高版本.如果您运行的是macOS的早期版本,则可以使用其他打包系统(例如Homebre ...

  2. Mac安装并运行 nginx

    小白,刚买的 Mac,在自己摸索着装环境和软件,遇到很多问题,简单记录一下 1. 安装 brew /usr/bin/ruby -e "$(curl -fsSL https://raw.git ...

  3. mac安装Hadoop3.2.1教程(超详细)

    由于课程需要和工具限制,需要在mac上安装Hadoop,参考了网上的教程,总结了用terminal安装Hadoop3.2.1以及运行第一个Wordcount程序的过程.这里默认mac的terminal ...

  4. Linux环境下安装及部署Nginx教程

    一.安装教程 1.官网下载地址:nginx: download 2.下载教程: 1)选择Stable version版本下载到本地(该版本为Linux版本),下载完成后直接在本地解压后放入linux系 ...

  5. Windows环境下安装及部署Nginx教程

    一.安装Nginx教程 1.官网下载地址:https://nginx.org/en/download.html 2.下载教程:选择Stable version版本下载到本地 3.下载完成后,解压放入本 ...

  6. linux下安装两个nginx教程,在linux系统下安装两个nginx的简单方法

    在linux系统下安装两个nginx的简单方法 发布时间:2017-03-09 12:08 来源:互联网 当前栏目:web技术类 在linux下安装nginx的时候,一般在./configure的阶段 ...

  7. 解决M1芯片Mac安装PS2021卡启动页问题,M1芯片Mac安装PS2021和PS2020教程!

    最新,很多用户可能都看到了M1芯片Mac安装PS2020和PS2021的安装更新,并且第一时间都安装了,但是很多M1芯片用户安装后都相继的出现了打开PS 一直卡在启动页界面,怎么都加载不进去,从而导致 ...

  8. mac安装win10_苹果电脑Mac安装Win10双系统教程

    我们知道,苹果电脑搭载的都是自家的MAC OS系统,虽然在使用体验上十分流畅,尤其是剪辑人员,在苹果使用剪辑软件简直是福音,大大提升了工作效率.不过苹果MAC OS系统在软件方面并不全面,往往很多软件 ...

  9. Mac安装JDK1.8详细教程

    介绍一下如何在Mac里面安装jdk 由于系统各个版本的差异,所以贴出来我的系统版本 下面介绍一下如何安装JDK 先去官网下载自己需要的版本,jdk下载官方网址 如下图所示,选择Accept Licen ...

最新文章

  1. Entity Framework 6以Code First方式搭建Sqlite数据库环境
  2. Shell替换:Shell变量替换,命令替换,转义字符
  3. 使用 .toLocaleString() 轻松实现多国语言价格数字格式化
  4. c语言编写modbus程序,C语言编写modbus协议
  5. [Swift]LeetCode1043. 分隔数组以得到最大和 | Partition Array for Maximum Sum
  6. B+树 范围查询_为什么 MySQL 使用 B+ 树,而不是 B 树或者 Hash?
  7. C/C++的memset函数的说明和使用
  8. goeasy服务器发送(发布)消息,python服务端使用GoEasy实现websocket消息推送
  9. 几款实用的linux工具
  10. Python3爬取搜狗微信公众号
  11. 美信科技冲刺A股上市:拟募资4亿元,公司及董事长张定珍曾遭处罚
  12. 2w 字长文带你搞懂 Linux 命令行
  13. 【iOS】—— 多线程编程八重曲之(二)- Pthread
  14. HSB”、lab、CMYK、RGB有什么区别
  15. android 闪光灯程序,如何在Android中以编程方式打开前闪光灯?
  16. 轴承故障诊断之时域指标
  17. table和div的比较
  18. Ubuntu 20.04折腾markdown编辑器remarkable血泪史
  19. Fedora10下AMD,Nvidia,Intel显卡驱动安装指南
  20. php-tanita,♥【停更】 ♥【 鉴于有些人把分享了的二次分享到别的论坛在此停更】♥♥【Tanitas8专贴】♥♥...

热门文章

  1. 提示删除身份证临时图像信息失败,请检查!解决方案
  2. zzulioj1103: 平均学分绩点(函数专题)
  3. dpdk eal初始化流程梳理
  4. 三、Qt界面设计之内置图标
  5. vue+elementui+lodop打印表格
  6. Spring 框架源码(二) 事务Transaction源码深度解析
  7. cmd安装Chocolatey
  8. cinder手动安装
  9. 2021 年山东省职业院校技能大赛中职组“网络安全” 赛项
  10. som聚类 matlab,使用SOM对数据进行聚类