1、更新brew峦睡,用來保障安裝的nginx是最新版本
brew update
2、安裝nginx
brew install nginx
安裝的nginx會(huì)保存到:/usr/local/Cellar/nginx
nginx配置文件在:/usr/local/etc/nginx/nginx.conf
3完箩、啟動(dòng)nginx
sudo nginx
4赐俗、注意事項(xiàng)
nginx配置如下:
location / {
root? /Users/xxxx/Documents/html/;
index? index.html index.htm;
deny all;
修改root地址后,應(yīng)展示html文件夾下的index.html頁面弊知,但是訪問卻是403 Forbidden報(bào)錯(cuò)阻逮,這是因?yàn)椋?/p>
根據(jù)nginx的 location匹配規(guī)則,當(dāng)一個(gè)location 匹配成功以后秩彤,會(huì)執(zhí)行該location下指定的root路徑叔扼。如果該root路徑存在并且具有可執(zhí)行的權(quán)限,既可以成功展示對(duì)應(yīng)的index.html(歡迎頁)漫雷,否則跳轉(zhuǎn)默認(rèn)nginx歡迎頁面或者報(bào)錯(cuò)404
個(gè)例子中root路徑是存在的瓜富,但是問題就是有沒有執(zhí)行權(quán)限。給該root路徑的所有文件夾賦予777的權(quán)限降盹,問題解決
chmod 777 /Users/xxx/Documents
chmod 777 /Users/xxx/Documents/html