当前位置:

mac-安装nginx,实现前端访问80端口后端转8080

访客 2024-02-04 991 0

mac下默认无法访问1000以下的端口,前端工程在访问时,要么修改成后端的端口,要么用nginx做一层代理,下面介绍用nginx做代理的方法

1、安装nginx,前提安装了homebrew(安装方法),

2、安装nginx,

brewinstallnginx

3、修改配置文件,nginx配置文件位置:/opt/homebrew/etc/nginx/nginx.conf

nginx默认端口是8080,需要修改成80,部门截图如下,红色为修改的地方

server{

listen80;

server_namelocalhost;

#charsetkoi8-r;

#access_loglogs/host.access.logmain;

location/{

proxy_passhttp://127.0.0.1:8080;

}

}

4、启动nginx

sudonginx

5、查询nginx是否启动成功

ps-ef|grepnginx

结果如下,表示启动成功,其中

nginx:materprocessnginx表示nginx的master线程

nginx:workerprocess表示nginx的工作线程线程

  • 0925051010:06上午??0:00.00nginx:masterprocessnginx
  • -29250692505010:06上午??0:00.00nginx:workerprocess
  • 5019254930199010:06上午ttys0000:00.00grepnginx
  • 6、停止nginx

    sudonginx-sstop

    7、修改配置文件后,让配置生效

    sudonginx-sreload

    发表评论

    • 评论列表
    还没有人评论,快来抢沙发吧~