搭建靜態(tài)站點(diǎn)
(推薦教程:nginx教程)
配置如下:
# 虛擬主機(jī)server塊 server { # 端口 listen 8080; # 匹配請(qǐng)求中的host值 server_name localhost; # 監(jiān)聽請(qǐng)求路徑 location / { # 查找目錄 root /source; # 默認(rèn)查找 index index.html index.htm; } }
相關(guān)字段
-
server 配置虛擬主機(jī)的相關(guān)參數(shù),可以有多個(gè)
-
server_name 通過請(qǐng)求中的host值,找到對(duì)應(yīng)的虛擬主機(jī)的配置
-
location 配置請(qǐng)求路由,處理相關(guān)頁面情況
-
root 查找資源的路徑
配置完成后執(zhí)行 nginx -t
命令,查看是否有錯(cuò)誤,如果出現(xiàn)如下提示,就表示成功了。
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
然后執(zhí)行 nginx -s reload
命令更新Nginx配置文件
這時(shí)候打開瀏覽器 輸入 localhost:8080
應(yīng)該就能看到你的頁面了
-
nginx -t 檢查配置文件是否有語法錯(cuò)誤
-
nginx -s reload 向主進(jìn)程發(fā)送信號(hào),重新加載配置文件
-
nginx -s stop 快速關(guān)閉
-
nginx -s quit 等待工作進(jìn)程處理完成后關(guān)閉