Nginx Docker容器上的静态网页缺lessCSS

我正在尝试使用Nginx托pipeDocker容器上的Swagger UI。

当我通过hostAddress.com访问我的网页时,它以纯文本forms返回网页,并检查它是否告诉我它无法find任何javascript或css文件,尽pipe它们似乎存在于容器中,因为我已将ssh放入容器去检查。

我的dockerfile

FROM nginx COPY src /usr/share/nginx/html COPY config/nginx.conf /etc/nginx EXPOSE 80 

nginx.config

 events { worker_connections 4096; ## Default: 1024 } http { server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html index.htm; include /etc/nginx/mime.types; location /swagger { try_files $uri /index.html; } #Static File Caching. All static files with the following extension will be cached for 1 day location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { expires 1d; } } } 

在这里你可以做到这一点。

就像它被提到的评论,你可以从https://github.com/ianneub/docker-swagger-ui/blob/master下载工件

  • 创build一个目录说ngix
  • 将Dockerfile , run.sh复制到该目录中
  • 编辑Dockerfile以进行自定义,您需要更改位置,如下所示:
 FROM nginx:1.9 ENV SWAGGER_UI_VERSION 2.1.2-M2 ENV URL **None** RUN apt-get update \ && apt-get install -y curl \ && curl -L https://github.com/swagger-api/swagger-ui/archive/v${SWAGGER_UI_VERSION}.tar.gz | tar -zxv -C /tmp \ && mkdir /usr/share/nginx/html/swagger \ && cp -R /tmp/swagger-ui-${SWAGGER_UI_VERSION}/dist/* /usr/share/nginx/html/swagger \ && rm -rf /tmp/* COPY run.sh /run.sh CMD ["/run.sh"] 
  • 如果您将上述更改与原始Dockerfile进行比较,则会在第9,10行中进行更改,以包含额外的path,即大swagger 。 当然,你可以根据需要改变。

接下来,运行以下docker命令来构build并运行

构build图像:

 docker build -t myswagger . 

运行

 docker run -it --rm -p 3000:80 --name testmyswagger -e "URL=http://petstore.swagger.io/v2/swagger.json" myswagger 

现在你应该可以使用http:// localhost:3000 / swagger / index.html来访问你的swagger了