admin 管理员组文章数量: 887021
macbookpro
背景:测试前后端分离项目中的websoket实时显示动态日志信息,只是单纯在工具中启动前后端项目,暂时无法完成通信,所以打算自己安装一个Nginx,然后再进行测试。我的电脑是基于arm架构的,在网上也没有搜到Nginx有arm架构的,搜了几个都是用brew方式安装的,所以打算用brew的方式安装一下
第一步:利用brew安装Nginx:
安装命令
brew install nginx
安装完显示如下;
brew install nginx ✔ base Py at 11:35:12
Running `brew update --auto-update`...
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Casks
acquia-dev lunastudio sketchpacks
alipay-development-assistant macdjview snappy
anonymousvpn macfusion-ng sneek
avira-antivirus metadatics soda-player
between mikogo stack-exchange-notifier
boxer mindmaster starleaf
catoclient mpeg-streamclip startninja
cryptonomic-galleon mutify syncsettings
depthmapx nautilus tempo
eliot nym-wallet the-tagger
firmaec onepile tipp10
flume openloco tn3270-x
gobdokumente oxwu today-scripts
google-drive-file-stream paddle-easydl ujam
houseparty phew universal-battle
hyperdock photo-supreme-single-user vofa-plus
hyperswitch physicseditor voicemac
idefrag polycom-content webarchiveextractor
igetter polycom-realpresence wercker
iota-wallet questrade-iq-edge wxcrafter
jqbx quicksync zebra2
kieler sdrdx zoomus
kryoflux simplediagrams
libreelec-usb-sd-creator simplelink-msp432-sdkYou have 1 outdated formula installed.
You can upgrade it with brew upgrade
or list it with brew outdated.==> Fetching dependencies for nginx: pcre2
==> Fetching pcre2
==> Downloading .42.arm64_ventura.
######################################################################## 100.0%
==> Fetching nginx
==> Downloading .23.4.arm64_ventura
######################################################################## 100.0%
==> Installing dependencies for nginx: pcre2
==> Installing nginx dependency: pcre2
==> Pouring pcre2-10.42.arm64_ventura.bottle.tar.gz
🍺 /opt/homebrew/Cellar/pcre2/10.42: 230 files, 6.2MB
==> Installing nginx
==> Pouring nginx-1.23.4.arm64_ventura.bottle.tar.gz
==> Caveats
Docroot is: /opt/homebrew/var/wwwThe default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.nginx will load all files in /opt/homebrew/etc/nginx/servers/.To start nginx now and restart at login:brew services start nginx
==> Summary
🍺 /opt/homebrew/Cellar/nginx/1.23.4: 26 files, 2.2MB
==> Running `brew cleanup nginx`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> nginx
Docroot is: /opt/homebrew/var/wwwThe default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.nginx will load all files in /opt/homebrew/etc/nginx/servers/.To start nginx now and restart at login:brew services start nginx
由上面的打印信息可以看到
安装成功后,在这个目录下可以看到Nginx的配置文件的路径
/opt/homebrew/etc/nginx
Nginx的安装路径
/opt/homebrew/Cellar/nginx/1.23.4
第二步:启动
/opt/homebrew/Cellar/nginx/1.23.4/bin下执行./nginx即可
查看进程
ps -ef|grep nginx
显示如下,则表示Nginx启动起来了
第三步:验证Nginx的访问
验证Nginx的启动是否正常,浏览器直接输入localhost:8080,显示如下,则表示启动正常
第四步:修改Nginx的错误日志级别
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;直接开启info级别的日志
在/opt/homebrew/Cellar/nginx/1.23.4/下新建logs文件夹
然后重启Nginx
重启的命令
./nginx -s reload
然后可以查看errorr.log的日志
第五步:开启access日志
access log是nginx的访问日志,其记录了每个用户访问nginx服务的日志信息,通过该日志我们可以分析用户的浏览行为,各子系统的访问热度
要开启access很简单,只需要开启log_format和access_log参数即可
http {include mime.types;default_type application/octet-stream;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;
关于Nginx的配置文件一些参数的说明
参数名称 | 说明 |
---|---|
$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 | 记录客户端访问信息,例如:浏览器、手机客户端等 |
本文标签: macbookpro
版权声明:本文标题:macbookpro 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1693817369h244310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论