使用 docker 鏡像 nginx:1.17.0-alpine
構建容器。將主機端口 8080 映射到容器的 80 端口,因爲
採用默認的配置訪問目錄名不加 / 時,不會返回其中的 index 內容,因此須要額外配置。以下的配置適用於同端口映射的情形,當宿主機的端口和容器的端口不一致時,訪問 http://localhost:8080/abc
, 則會重定向到 http://localhost/abc/
, 這顯然不是咱們想要的結果。html
listen 80; location / { index index.html index.htm; try_files $uri $uri/ =404; }
因而我去問搜索引擎,終於找到了此情形下的配置。nginx
location / { index index.html index.htm; } location ~ ^.*[^/]$ { try_files $uri @rewrite; } location @rewrite { return 302 $scheme://$http_host$uri/; }
參考 https://serverfault.com/quest...docker