mac安装nginx

mac安装nginx

涉及的工具及命令

  • homebrew: 一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能

  • 涉及的brew命令

    brew update // 升级homebrew
    brew search nginx // 查询要安装的软件是否存在
    brew info nginx // 查看nginx包的详细信息
    brew install nginx // 安装nginx
    
  • nginx

    sudo nginx -s stop // 停止nginx
    nginx // 启动nginx
    sudo nginx -s reload // 重启nginx
    

安装

brew install nginx

查看详细信息

brew info nginx

info信息说明:

  • nginx: stable 1.19.6 (bottled), HEAD 版本信息

  • Built from source on 2021-02-14 at 14:13:05 说明已安装,否则会显示 Not installed

  • Docroot is: /usr/local/var/www Docroot默认文件路径

  • The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
    nginx can run without sudo. 默认端口号,也可以在nginx.conf中修改

  • nginx will load all files in /usr/local/etc/nginx/servers/. 这个目录下的所有文件都会被加载

安装完后运行

nginx  // 启动成功是没有成功提醒的

验证是否启动成功

  • 浏览器打开, 显示如下图便是成功

    http://localhost:8080/
    

  • 也可以通过进程,看下nginx是否启动成功,成功会显示nginx占用该进程
lsof -i:8080

注意事项

  • 端口占用

    • 错误信息: nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

    • 错误原因:端口已经被使用

    • 解决步骤:

      lsof -i:8080 // 查看是被哪个程序占用, 可以选择更换端口
      kill -9 32576 // 如果该进程不需要,直接杀掉占用的进程
      sudo nginx -s reload // 重启nginx
      
posted @ 2021-02-15 21:05  青春大蜗牛  阅读(2968)  评论(0编辑  收藏  举报