1. 查看brew 的版本
$ brew --version
  1. 搜索nginx
$ brew search nginx
  1. 安装 nginx
$ brew install nginx

==> nginx
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd 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:
nginx

  1. 查看nginx配置文件目录
$ open /usr/local/etc/nginx/
  1. 查看nginx被安装到的目录
$ open /usr/local/Cellar/nginx
  1. 启动 nginx
$ /usr/local/Cellar/nginx/1.17.7/bin/nginx
  1. 关闭 nginx
$ /usr/local/Cellar/nginx/1.17.7/bin/nginx -s stop
  1. 重新启动
$ /usr/local/Cellar/nginx/1.17.7/bin/nginx -s reload
  1. 查看访问日志、错误日志文件
$ cd /usr/local/var/log/nginx/
$ tail -f access.log
$ tail -f error.log
  1. 查看 nginx 相关文件
$ nginx -V
  1. 通过浏览器访问 http://localhost/
    在这里插入图片描述
遇到的问题

fengruizhideMacBook-Pro:work-manager-web fengrz$ brew install nginx
Updating Homebrew…
Error: The following directories are not writable by your user:
/usr/local/share/man/man5
/usr/local/share/man/man7
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/man/man5 /usr/local/share/man/man7
And make sure that your user has write permission.
chmod u+w /usr/local/share/man/man5 /usr/local/share/man/man7

  • 查看目录权限
$ ls -l /usr/local/share/man/

在这里插入图片描述

  1. 修改文件目录的所有者和群组
$ sudo chown -R fengrz:admin /usr/local/share/man/
  1. 修改后的结果,如图在这里插入图片描述
配置域名
  1. 配置本地域名路由指向
$ sudo vim /etc/hosts

127.0.0.1 thnm.fengrz.com
127.0.0.1 thnms.fengrz.com

  1. 配置域名
$ cd /usr/local/etc/nginx
$ mkdir vhosts
$ cd vhosts
$ vim thnm.fengrz.com.conf 
  • thnm.fengrz.com.conf 内容如下
  • thnm.fengrz.com server 配置
server {
    listen       80;
    server_name  thnm.fengrz.com;

    location / {
        root   /Users/fengrz/data/project/work-manager-web;
        index  index.html index.htm;
    }
    location /api {
        add_header 'Access-Control-Allow-Origin' '*';
        proxy_pass http://thnms.fengrz.com;
    }

}
  • thnms.fengrz.com server 配置
server {
    listen       80;
    server_name  thnms.fengrz.com;
        location / {
                root html;
                index index.html index.htm;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Real-Port $remote_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass   http://127.0.0.1:4521/;

        }
        location /api/ {
                root html;
                index index.html index.htm;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Real-Port $remote_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass   http://127.0.0.1:4521/;

        }


        location /bind/ {
                root html;
                index index.html index.htm;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Real-Port $remote_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass   http://127.0.0.1:4521/;

        }

}

  1. 编辑主配置文件 nginx.conf

include vhosts/*.conf;

在这里插入图片描述

  1. 检查配置文件是否正确
$ /usr/local/Cellar/nginx/1.17.7/bin/nginx -t
  1. 重启 nginx
$ /usr/local/Cellar/nginx/1.17.7/bin/nginx -s reload
  1. 启动浏览器 访问 http://thnms.fengrz.com

在这里插入图片描述

GitHub 加速计划 / br / brew
40.41 K
9.47 K
下载
🍺 The missing package manager for macOS (or Linux)
最近提交(Master分支:1 个月前 )
90a90b30 3 个月前
47b1cab7 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐