Mac使用brew安装nginx,并解决端口访问权限问题

1、安装

brew install nginx

2、修改配置文件

sudo vi /usr/local/etc/nginx/nginx.conf

修改默认的8080端口为80

修改日志文件地方
	error_log  logs/error.log;

	pid        logs/nginx.pid;

	access_log  logs/access.log;

按上面修改后日志文件在/usr/local/opt/nginx/logs

3、修改管理员权限

sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx

4、加上launchctl控制

mkdir -p ~/Library/LaunchAgents

cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

5、启动nginx

sudo nginx #启动

sudo nginx -t #测试配置文件是否有错

sudo nginx -s reload #重启nginx

6、问题

如果出现nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx/nginx.pid",则需要
	sudo nginx -c /usr/local/etc/nginx/nginx.conf
	sudo nginx -s reload
posted @ 2017-09-04 22:28  fengzp  阅读(13524)  评论(0编辑  收藏  举报