nginx在mac中安装配置启动

本文介绍了如何使用Homebrew在Mac上安装Nginx,包括下载安装步骤、启动、重启和关闭Nginx的命令,以及如何指定配置文件和错误日志路径。通过Brew管理Nginx使得配置和维护变得更加便捷。

brew安装

下载安装

启动、重启和关闭

nginx -h

  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/Cellar/nginx/1.19.10/--默认安装路径
  -e filename   : set error log file (default: /usr/local/var/log/nginx/error.log) --默认错误日志
  -c filename   : set configuration file (default: /usr/local/etc/nginx/nginx.conf) --默认配置文件
  -g directives : set global directives out of configuration file

启动

cd /usr/local/Cellar/nginx/1.21.4/bin

./nginx -c /usr/local/etc/nginx/nginx.conf

或者直接启动:/usr/local/Cellar/nginx/1.21.4/bin/nginx -c /usr/local/etc/nginx/nginx.conf

Mac安装配置Nginx和PHP可以按照以下步骤进行: 1. 安装Homebrew:Homebrew是Mac上的包管理器,可以简化安装过程。打开终端,并执行以下命令安装Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 安装Nginx:使用Homebrew安装Nginx,运行以下命令: ``` brew install nginx ``` 3. 配置Nginx:默认情况下,Nginx配置文件位于`/usr/local/etc/nginx/nginx.conf`。您可以根据需要编辑该文件,配置服务器块等。 4. 启动Nginx:执行以下命令启动Nginx: ``` sudo nginx ``` 5. 安装PHP:使用Homebrew安装PHP,运行以下命令: ``` brew install php ``` 6. 配置PHP:PHP的配置文件位于`/usr/local/etc/php/{版本号}/php.ini`。您可以根据需要编辑该文件,配置PHP的相关设置。 7. 启动PHP-FPM:PHP需要通过FastCGI Process Manager(PHP-FPM)与Nginx进行通信。执行以下命令启动PHP-FPM: ``` sudo php-fpm ``` 8. 配置Nginx以使用PHP:编辑Nginx配置文件`/usr/local/etc/nginx/nginx.conf`,找到`location`块,并将其修改为: ``` location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ``` 9. 重启Nginx:执行以下命令重启Nginx,使配置生效: ``` sudo nginx -s reload ``` 现在,您应该已经成功安装配置Nginx和PHP。您可以在浏览器中访问`http://localhost`来测试是否正常工作。如果您在其他目录下放置了PHP文件,请确保在Nginx配置文件中正确指定了根目录。 希望这些步骤能帮助到您!如果您有任何进一步的问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值