访问docker容器中的项目路由,会先经过nginx,然后才是web框架的路由,所以ngxin上配置的路由会比项目容器服务中的路由更高效。
大家可以测试看看。
1、nginx挂载相应的静态文件目录,这里用的是docker来部署服务的
nginx-host:
build: ./nginx
image: nginx-host
restart: always
ports:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
volumes:
- /root/app/yingjia-front-end/front/:/var/www/YingJia
container_name: nginx-host
2、nginx配置文件中设置uptream映射
location /mobile/index.html {
alias /var/www/YingJia/guotou/dist/index.html;
}
3、需要重新创建启动nginx-host容器,不然路径挂载不过去
docker-compose up xxxx
记住一定要重新up容器,重启容器是没有用的
浏览器上访问:域名+/mobile/index.html