mac下安装配置本地nginx

mac下安装配置本地nginx

1. 前提

必须安装了homebrew,可在终端输入命令brew -v查看是否已经安装,如果输入指令出现版本号说明已经安装成功

2. 步骤

1. 查看是否已经安装nginx
 brew search nginx
2. 安装
 brew install nginx
3. 启动nginx
nginx

默认端口是8080,访问http://localhost:8080/ 就能看到nginx在本计算机搭建的服务器。
在这里插入图片描述

4. 查看nginx安装目录
 open /usr/local/etc/nginx/

在这里插入图片描述

5. 修改配置nginx,解决跨域
server {
  # 需要被监听的端口号,前提是此端口号没有被占用,否则在重启 Nginx 时会报错
  listen       8888;
  # 服务名称,无所谓
  server_name  localhost;

  # 上述端口指向的根目录
  root D:/work/codet;
  # 项目根目录中指向项目首页
  index index.html;

  client_max_body_size 20m; 
  client_body_buffer_size 128k;

  # 由于路由的资源不一定是真实的路径,无法找到具体文件
  # 所以需要将请求重写到 index.html 中,然后交给真正的 Vue 路由处理请求资源
  location / {
      proxy_pass https://localhost:8080/;
  }
  # 配置你要访问的服务器地址
  location /grafana/ {
      proxy_pass https://192.128.29.102/grafana/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header   Cookie $http_cookie;
      # for Ajax
      #fastcgi_param HTTP_X_REQUESTED_WITH $http_x_requested_with;
      proxy_set_header HTTP-X-REQUESTED-WITH $http_x_requested_with;
      proxy_set_header HTTP_X_REQUESTED_WITH $http_x_requested_with;
      proxy_set_header x-requested-with $http_x_requested_with;
  }

  location /audit-apiv2{
      proxy_pass https://192.128.29.102/audit-apiv2/;
  }
}
6. 重启nginx
   nginx -s reload
7. 如果要快速停止nginx
   nginx -s stop
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值