在Mac上使用nginx

2023-01-19  本文已影响0人  iTonnnnnni_2022

首先查看自己的mac里是否已经安装了nginx

% nginx -v

没有的话,使用brew安装

% brew install nginx

安装完毕,启动

% sudo nginx

默认的文件存放在/usr/local/var/www, 去检查应该有一个index.html. 如果没有建立一个最简单的

保存到那个目录下。打开浏览器,在地址栏中输入 localhost 查看结果.

如果打不开文件,则到/usr/local/etc/nginx目录下检查配置文件 nginx.conf

查看http -> server -> listen 端口为多少。可能为8080

再次打开浏览器输入 localhost:8080 此时应可以打开文件 index.html

修改端口为80. (查看mac上应没有安装其他web服务器如apache, 如果有要先卸载)

停止nginx:

% sudo nginx -s stop 再次启动nginx 

或者用下面的命令让nginx重新装载设定文件:

% sudo nginx -s reload

用浏览器打开网页: localhost. 成功!

注: 让nginx自动启动

% brew services start nginx (尚未实验是否可行)

上一篇 下一篇

猜你喜欢

热点阅读