brew安装Nginx + php nginx 配置
一、brew安装Nginx
- 安装
brew install nginx
- 查看安装信息
brew info nginx
二、Nginx启动和停止
1.启动服务:sudo nginx
2.停止服务:sudo nginx -s stop
三、其它常用命令
sudo nginx 启动服务
sudo nginx -s reload 重新加载
sudo nginx -s reopen 重新启动
sudo nginx -s quit 退出(处理完事情走)
open /opt/homebrew/etc/nginx/ 查看nginx安装目录
四、Nginx配置及路径
1、基本路径
1.网站存放路径
/opt/homebrew/var/www
2.Nginx配置文件路径
/opt/homebrew/etc/nginx/nginx.conf
3.服务配置文件
/opt/homebrew/etc/nginx/servers/
4.后台进程守护,如果您不想要/不需要后台服务,您可以运行:
/opt/homebrew/opt/nginx/bin/nginx -g守护进程关闭;
2、Nginx配置—待编辑ing
Nginx配置文件路径
/opt/homebrew/etc/nginx/nginx.conf
服务配置文件
/opt/homebrew/etc/nginx/servers/
五、My Mac 提示及配置文件路径
Docroot is: /opt/homebrew/var/www
The 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 restart nginx after an upgrade:
brew services restart nginx
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/nginx/bin/nginx -g daemon off;
// 翻译:
// Docroot是:/opt/homebrew/var/www
// 默认端口已在/opt/homebrew/etc/nginx/nginx中设置。配置为8080,以便
// nginx可以在没有sudo的情况下运行。
// nginx将加载/opt/homebrew/etc/nginx/servers/中的所有文件。
// 要在升级后重新启动nginx,请执行以下操作:
// brew服务重新启动nginx
// 或者,如果您不想要/不需要后台服务,您可以运行:
// /opt/homebrew/opt/nginx/bin/nginx -g守护进程关闭;
nginx 配置
server {
#监听端口
listen 80;
#虚拟主机域名
server_name www.test.com;
#网站根目录
root /Users/aaa/wroot/test;
#定义路径下默认访问的文件名
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
#打开目录浏览功能,可以列出整个目录
#autoindex on;
}
access_log /usr/local/var/log/www.test.com-access.log main;
error_log /usr/local/var/log/www.test.com-error.log error;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
链接来源:http://www.mjdg.store/articles/2022/12/03/1670062521772.html