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 @ 2024-02-21 19:47  秋夜雨巷  阅读(93)  评论(0编辑  收藏  举报