配置server代碼段:
server { server_name www.meiduo.site; listen 8080; root /home/python/Desktop/meiduo_mall_admin/dist; index index.html; }
其中:
server_name : 監聽的域名
listen : 監聽的端口
root : 網站的根路徑
index : 默認訪問的文件
配置location代碼段:
server { server_name www.meiduo.site; listen 8080; location / { root /home/python/Desktop/meiduo_mall_admin/dist; index index.html; } }
其中:
location字段需要寫在server字段內,一個server字段可以包含多個location字段。
其余屬性意思同上。
注意:
location _ {} :這里的_表示匹配規則,加上=_表示嚴格匹配,不加_表示不嚴格匹配。
例如:
server { server_name www.meiduo.site; listen 8080; location / { root /home/python/Desktop/meiduo_mall_admin/dist; index index.html; } # 表示只有輸入www.meiduo.site/image/時,才走這個location location =/image/ { root /home/python/Desktop/meiduo_mall_admin/dist; index index.html; } }
在配置完配置文件以后,需要測試一下語法是否出錯和重新加載配置文件。
sudo nginx -t
sudo nginx -s reload
