Fork me on GitHub

Mac安装Nginx

Nginx

安装

#查找nginx版本
brew search nginx
#安装nginx,默认是最新版本
brew install nginx
#指定版本安装方式为:nginx@版本号
brew install nginx@1.12.2

#卸载nginx
brew uninstall nginx
brew uninstall nginx@版本号

#查看已安装的软件
brew list
#查看nginx安装信息(eg:安装目录)
brew info nginx

image

查看nginx信息

#查看nginx安装信息(eg:安装目录)
brew info nginx
#网页目录添加软链接
ln -s /opt/homebrew/var/www /Users/yuqiu/software/nginx_www

image
网页目录: /opt/homebrew/var/www
默认配置文件:/opt/homebrew/etc/nginx/nginx.conf
会被加载的配置文件: /opt/homebrew/etc/nginx/servers/
日志文件位置: /opt/homebrew/var/log/nginx
image

nginx常用命令

# brew启动nginx服务
brew services start nginx
brew services stop nginx
brew services restart nginx

# nginx原生常用命令启动、停止、重新加载配置文件(不推荐)
nginx #启动nginx
nginx -s reload #重新加载配置文件 ,热加载配置文件
nginx -s quit #:推荐 待nginx进程处理任务完毕进行停止
nginx -s stop #:先查出nginx进程id再使用kill命令强制杀掉进程。

#进程查询
ps aux|grep nginx
ps -ef|grep nginx

支持php

nginx配置

#修改nginx配置文件
vi /opt/homebrew/etc/nginx/nginx.conf
#添加如下配置,这里不能有root,有的话也要和根目录一样
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9999;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

#修改完检测配置文件
nginx -t

image

php-fpm配置

#修改配置文件php-fpm.conf
vi /opt/homebrew/etc/php/7.4/php-fpm.conf
#添加如下内容
#配置日志文件路径
[global]
error_log = /usr/local/var/log/php-fpm.log

#这个监听文件在php-fpm.d/www.conf中,有的版本写在php-fpm.conf
vi /opt/homebrew/etc/php/7.4/php-fpm.d/www.conf
#修改监听端口,需要与nginx配置的fastcgi_pass项匹配
[www]
listen = 127.0.0.1:9999

image

启动php-fpm

#关闭fpm
killall php-fpm
#启动fpm
php-fpm -D
#重启nginx
brew services restart nginx

测试

<?php
echo phpinfo();

php解析成功
image

posted @   秋夜雨巷  阅读(181)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2019-02-21 启动mysql5.7异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
点击右上角即可分享
微信分享提示