0
点赞
收藏
分享

微信扫一扫

mac pro M1(ARM)安装:Nginx安装并开启错误、访问日志


0.引言

最近正好在mac m1中安装Nginx,特作记录,以供后续参考

1. homebrew方式安装

mac m1安装Nginx最方便快捷的方式是通过homebrew安装,当前前提是需要先安装homebrew

1、安装Nginx,执行指令

brew install nginx

mac pro M1(ARM)安装:Nginx安装并开启错误、访问日志_arm


如上图所示可以看到

Nginx配置文件路径:​​/opt/homebrew/etc/nginx/nginx.conf​​​ 安装路径:​​/opt/homebrew/Cellar/nginx​

2、启动Nginx,执行指令

nginx

3、浏览器方式​​localhost:8080​

mac pro M1(ARM)安装:Nginx安装并开启错误、访问日志_nginx_02


安装成功!

1.1 开启错误日志

1、修改配置文件

vim /opt/homebrew/etc/nginx/nginx.conf

2、开启错误日志,这里提供了三种等级,这里我为了测试,直接开启info等级

#error_log  logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;

3、重启Nginx

nginx -s reload

其他指令

# 关闭Nginx
nginx -s stop

4、如果第一次开启可能会报错

​nginx: [emerg] open() "/opt/homebrew/Cellar/nginx/1.21.6/logs/error.log" failed (2: No such file or directory)​

解决办法很简单,只需要将logs文件夹创建出来就好了

mkdir /opt/homebrew/Cellar/nginx/1.21.6/logs

5、查看日志

cat /opt/homebrew/Cellar/nginx/1.21.6/logs/error.log

mac pro M1(ARM)安装:Nginx安装并开启错误、访问日志_arm_03

1.2 开启access日志

access log是nginx的访问日志,其记录了每个用户访问nginx服务的日志信息,通过该日志我们可以分析用户的浏览行为,各子系统的访问热度

要开启access很简单,只需要开启​​log_format​​​和​​access_log​​参数即可

1、修改配置文件

vim /opt/homebrew/etc/nginx/nginx.conf

修改内容

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log main;
}
}

参数

说明

$remote_addr

记录访问网站的客户端地址

$http_x_forwarded_for

当前端有代理服务器时,设置web节点记录客户端地址的配置

$remote_user

用来记录客户端用户名称

$time_local

用来记录访问时间与时区

$request

用来记录请求的http的方式与url

$request_time

用来记录请求时间

$status

用来记录请求状态;成功是200,未找到是404

$body_bytes_sent

记录发送给客户端文件主体内容大小

$http_referer

用来记录从那个页面链接访问过来的

$http_user_agent

记录客户端访问信息,例如:浏览器、手机客户端等

2、重启nginx

nginx -s reload

3、查看日志

cat /opt/homebrew/Cellar/nginx/1.21.6/logs/access.log

mac pro M1(ARM)安装:Nginx安装并开启错误、访问日志_macos_04


举报

相关推荐

0 条评论