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的工作线程线程
6、停止nginx
sudonginx-sstop
7、修改配置文件后,让配置生效
sudonginx-sreload