安裝
我們通過(guò)brew來(lái)安裝nginx
brew install nginx
我在安裝過(guò)程中出現(xiàn)一個(gè)小問(wèn)題,報(bào)了這樣一個(gè)錯(cuò)誤:
Error: Could not symlink share/man/man8/nginx.8 /usr/local/share/man/man8 is not writable.
從上面看大體意思就是/usr/local/share/man/man8
這個(gè)目錄對(duì)當(dāng)前用戶無(wú)寫(xiě)權(quán)限,所以我們給這個(gè)目錄加上就可以了
- 下圖為ls -l命令結(jié)果
drwxr-xr-x 38 SeanLiu admin 1292 2 13 17:28 man1
drwxr-xr-x 103 SeanLiu admin 3502 2 13 17:28 man3
drwxr-xr-x 7 root admin 238 1 22 18:31 man8
-rw-r--r-- 1 root admin 1583 2 10 08:19 whatis
- 執(zhí)行
sudo chown -R \
whoami` man8` - 最后執(zhí)行
brew link nginx
就好了
注意事項(xiàng):
- nginx默認(rèn)安裝路徑:
/usr/local/Cellar/nginx/1.10.3
- nginx配置文件路徑:
/usr/local/etc/nginx
- nginx啟動(dòng)命令
nginx
- 如果出現(xiàn)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
錯(cuò)誤悦昵,其實(shí)是8080端口被占用了畜眨,我們可以通過(guò)修改默認(rèn)端口來(lái)避免錯(cuò)誤:
vim /usr/local/etc/nginx/nginx.conf
server {
listen 8081; #修改這里為其他端口如8081
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
最后保存重新運(yùn)行
- 更改默認(rèn)web路徑
默認(rèn)路徑為/usr/local/Cellar/nginx/1.10.3/html
server {
listen 8081; #修改這里為其他端口如8081
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html; #修改這里的路徑為自己的路徑 如/Users/xxx/www
index index.html index.htm;
}
然后重啟nginx 執(zhí)行 nginx -s reload
就可以了
- 停止
首先查找到nginx的進(jìn)程號(hào):
ps -ef | grep nginx
root 713 1 0 00:15 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 717 713 0 00:15 ? 00:00:00 nginx: worker process
root 5345 4226 0 15:23 pts/1 00:00:00 grep --color=auto nginx
執(zhí)行命令 kill -QUIT 713
另外還有兩種:
快速停止
`kill -TERM 713`或者`kill -INT 713`
強(qiáng)行停止
pkill -9 nginx
- 驗(yàn)證nginx配置文件是否正確
nginx -t
出現(xiàn)下面則配置正確
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful