# Mac下安装nginx

# 必备工具

homebrewhttps://brew.sh/index_zh-cn.html (opens new window)(安装方法自行搜索)

安装完毕后代开命令行

# 步骤一:先更新homebrew

brew update
1

如果上面操作长时间没有任何动静,请更换镜像,参考清华镜像

https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/ (opens new window)

# 步骤二: 查看nginx信息

brew search nginx
1

# 步骤三: 安装nginx

brew install nginx
1

安装完毕 主页的文件在/usr/local/var/www 文件夹下 对应的配置文件地址在/usr/local/etc/nginx/nginx.conf

# 步骤四:运行nginx

nginx
1

nginx默认使用8080端口 如果发现端口被占用了,可以杀掉使用使用改端口的进程,也可以修改/usr/local/etc/nginx/nginx.conf 下的

http {
    server {
        listen       8181;
        server_name  localhost;

        #charset koi8-r;
        .....
        }
    }
1
2
3
4
5
6
7
8
9

# 重新启动nginx

nginx -s reload
1

成功看到欢迎页面~!(对应的html是/usr/local/var/www/index.html)