mac下修改nginx的Docroot

发表于: lnmp | 作者: | 日期: 2018/4/21 06:04

nginx使用brew安装,信息如下:


brew info nginx
nginx: stable 1.13.12 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.6.2 (7 files, 902KB)
Poured from bottle on 2014-12-18 at 21:03:14
/usr/local/Cellar/nginx/1.13.9 (23 files, 1.4MB)
Poured from bottle on 2018-03-11 at 11:01:32
/usr/local/Cellar/nginx/1.13.10 (23 files, 1.4MB) *
Poured from bottle on 2018-04-03 at 19:40:49
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb
==> Dependencies
Required: openssl ✔, pcre ✔
Optional: passenger ✘
==> Options
–with-passenger
Compile with support for Phusion Passenger module
–HEAD
Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don’t want/need a background service you can just run:
nginx

可以看到默认的docroot为 /usr/local/var/www,编辑nginx.conf文件,将其修改为 /Users/darkmi/Documents/sites/www 。

但是修改之后遇到了 403 Forbidden 错误,然后重新编辑nginx.conf 文件:


vim /usr/local/etc/nginx/nginx.conf

将nginx的启动用户修改为mac当前登录用户的用户名及组:

user darkmi staff;

然后重启nginx:

sudo nginx -s reload

重启之后 403 Forbidden 错误消失,可以访问静态文件,但是无法访问php文件,出现:no input file 的错误。

php使用了mac自带的7.1,版本如下:

php -v
PHP 7.1.14 (cli) (built: Feb 7 2018 18:33:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

接下来找到php-fpm的配置文件:

locate www.conf
/private/etc/php-fpm.d/www.conf
/private/etc/php-fpm.d/www.conf.default
/usr/local/Cellar/php@7.0/7.0.27_19/.bottle/etc/php/7.0/php-fpm.d/www.conf
/usr/local/Cellar/php@7.0/7.0.29/.bottle/etc/php/7.0/php-fpm.d/www.conf
/usr/local/etc/php/7.0/php-fpm.d/www.conf
/usr/local/etc/php/7.0/php-fpm.d/www.conf.default

因为我使用的是mac自带的php-fpm,所以选择第一个文件:


sudo vim /private/etc/php-fpm.d/www.conf

设置启动用户和组:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user’s group
; will be used.
user = darkmi
group = staff

然后重启:

sudo pkill php-fpm
sodo php-fpm

然后可以正常访问php文件。

: https://blog.darkmi.com/2018/04/21/3167.html

本文相关评论 - 1条评论都没有呢
Post a comment now » 本文目前不可评论

No comments yet.

Sorry, the comment form is closed at this time.