nginx功能之一可以啟動一個本地服務器,通過配置server_name和root目錄等來訪問目標文件
一. 下載
下載后解壓
二. 修改配置文件
nginx配置文件在 nginx-1.8.0\conf\nginx.conf
http {
gzip on;
#靜態文件
server {
listen 80;
server_name static.cnblog.com;
location / {
root G:/source/static_cnblog_com;
}
}
#html文件
server {
listen 80;
server_name 127.0.0.1 localhost;
location / {
root G:/source/html/mobile/dist;
index index.html index.htm;
}
}
}
如上圖可以配置多個server,這樣訪問localhost即訪問到了 G:/source/html/mobile/dist 目錄, 還可以開啟gzip,壓縮html
三. 啟動
注意不要直接雙擊nginx.exe,這樣會導致修改配置后重啟、停止nginx無效,需要手動關閉任務管理器內的所有nginx進程
在nginx.exe目錄,打開命令行工具,用命令 啟動/關閉/重啟nginx
start nginx : 啟動nginx
nginx -s reload :修改配置后重新加載生效
nginx -s reopen :重新打開日志文件
nginx -t -c /path/to/nginx.conf 測試nginx配置文件是否正確
關閉nginx:
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx
如果遇到報錯:
nginx -t -c /path/to/nginx.conf 測試nginx配置文件是否正確
關閉nginx:
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx
如果遇到報錯:
bash: nginx: command not found
有可能是你再linux命令行環境下運行了windows命令,
如果你之前是允許 nginx -s reload報錯, 試下 ./nginx -s reload
或者 用windows系統自帶命令行工具運行
