Mac 之 Nginx 安装

本文指导如何在Mac上使用Homebrew安装Nginx,涉及更新、查询、安装、目录设置、启动及配置文件修改,包括自动目录列表、字符集设置和PHP支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mac 之 Nginx 安装

参考

打开终端, 对 brew 进行更新

brew update

查询 Nginx 是否存在

brew search nginx

查看 Nginx 详情

brew info nginx

正式开始安装

brew install nginx

查看 Nginx 安装目录(是否如 info 所说)

open /usr/local/etc/nginx/ # 配置目录
open /usr/local/Cellar/nginx # 安装目录

启动 Nginx, 终端输入如下命令

nginx

修改 Nginx 配置

vim /usr/local/etc/nginx/nginx.conf

在 http 里面增加

# 开启目录文件列表
autoindex on;
# 显示出文件的确切大小, 单位是bytes
autoindex_exact_size off;
# 显示的文件时间为文件的服务器时间
autoindex_localtime on;
#设置字符集
charset utf-8,gbk;

添加 server 配置

server {
    ...
    location / {
        root   /Users/zhangsan/projects/;
        index index.php index.html index.htm;
    }

    location ~ \.php$ {
        root           /Users/zhangsan/projects/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    ...
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值