前言
今天在部署前端同事的靜態資源時遇到一個問題,靜態資源通過常規的 location / 方式無法正常打開,但是測試頁面可以正常訪問。
后來和前端同事了解得知,開發時選用的框架都需要依賴上一級目錄,所以訪問時需要配置 rewrite 。
目錄結構
- conf 配置
server {
listen 8888;
......
location / {
rewrite ^(.*) $scheme://$host:$server_port/tscp/ permanent; #此處的$server_port是當監聽不通端口時需配置
}
location /tscp/ {
root /home/fuhai/;
index portal/default/index.html; #靜態頁默認的訪問頁面
}
......