1.安裝nginx(需要先安裝Homebrew)。使用命令
brew install nginx
安裝nginx。
2.用命令
open /usr/local/Cellar/nginx
用訪達打開安裝路徑。
3.打開bin文件夾,雙擊nginx文件,啟動nginx,然后訪問http://localhost:8080/。
若出現如圖界面,則啟動nginx成功。
4.打開配置文件。用命令
open /usr/local/etc/nginx
打開配置文件所在路徑,再用文本編輯器打開nginx.conf文件進行編輯。
5.修改部署路徑為項目路徑。
如項目首頁路徑為/Users/luoyihao/projectName/main.html,projectName內包括項目用到的所有資源(包括圖片、css、js等),
則把第一個
location / {
root html;
index index.html index.htm;
}
修改為
location / { root /Users/luoyihao/projectName; index main.html; }
6.重新啟動nginx,使用命令
nginx -s reload
然后訪問http://localhost:8080/main.html即可。