mac 安装nginx及修改配置

安装说明说明:

  • 安装brew
终端执行:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
  • 安装nginx
终端执行:
brew install nginx
  • 安装成功后会有以下信息
Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/nginx/bin/nginx -g daemon off;
nginx的使用:

打开终端,然后~
1、重启nginx : sudo nginx -s reload
2、关闭nginx : sudo nginx -s stop
3、开启nginx : sudo nginx

修改nginx配置:

1、访达右键点击前往,输入/opt/homebrew/etc/nginx回车
2、找到 nginx.conf 文件
3、修改默认路径 为期望路径 ,例如:

修改前:
location / {
         root   html;
         index  index.html index.htm;
     }

修改后:
location / {
         listen       81 //端口号
         root   /Users/huijuanliu/Documents/www; //www目录不要直接在用户目录下,权限问题会有403,放在Documents文稿目录下可避免此问题
         index  index.html index.htm;
     }

4、保存,重启nginx(终端输入:sudo nginx -s reload)
5、浏览器输入http://localhost:81,显示修改后的页面路径,over~

*nginx启动后访问文件如果出现403,可在nginx.conf第一行加上

user root owner;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容