在 linode 与本地主机上使用 nginx、gunicorn、docker-compose 部署不一致的 CSS 渲染

问题描述

我正在使用上述组件部署应用程序。我正在部署一个 django/gunicorn 应用程序,使用 Nginx,使用 docker-compose。

它基于前端模板 (sb-admin),该模板在 sb-admin-2.min.css 中定义。我在 mystyle.css 中覆盖/补充了​​它。

基本上我构建我的图像,将它们推送到我的 dockerhub。然后我部署它们(通过使用 docker-compose pull 拉取图像),并使用 docker-compose up --no-build 运行它们(只是为了确保)。

您可以查看结果以及控制台详细信息。右边是本地部署,左边是linode。您可以从控制台看到两个加载 mystyle.css 的 GET 200 OK 响应(在加载 sb-admin-2.min.css 之后)。然而不知何故,结果在 linode 上的实际服务器部署上有所不同。

我试过了:

  • 从头开始多次。例如。我已经删除了 linode 服务器和本地机器上的所有容器/图像。然后我在本地重新构建它们,将它们推送到 dockerhub。然后拉动它们(在本地和 linode 上)。然后部署并访问页面 - 结果有些不同。我很漂亮,我正在拉/推/跑我认为我应该做的事情。

我什至不太确定如何解决这个问题 - 显然部署有效,但为什么结果不同?我应该如何调试这个?

dockerfile:

version: '3.9'

services:
  django:
    # since both build: & image: are present,the result of the build: instruction will be called whatever name we assign to image:
    image: franckit/${DJANGO_IMG_NAME}
    build:
      # everything relevent to that built is within /app
      context: ./app
      # specifying the Dockerfile to use,as it is not named Dockerfile
      dockerfile: Dockerfile.prod
      args:
        - "VERSION=${DJANGO_IMG_VERSION}"
      # using gunicorn as our webserver in front of Docker (manage traffic)
    command: "gunicorn myproject.wsgi:application --bind ${DJANGO_IP}:${DJANGO_PORT}"
    # expose only makes the port available on the Docker virtual network. Dfeault for django is 8000 so we'll just use that
    expose:
      - "${DJANGO_PORT}"
    # we'll dump the (runtime) envars in there.  to user buildtime envars,see this issue: https://stackoverflow.com/questions/64405332/docker-compose-env-file-only-loading-env-but-not-a-specific-name/64436008#64436008
    # short story being that you MUST name a file .env if you are to use those as build-time envars
    # env_file:
    #   - ./.env.prod
    volumes:
      - static_vol:/home/app/web/static

  # Nginx acts as a reverse proxy in front of our app. see /Nginx/Nginx.conf for details
  Nginx:
    image: franckit/my_Nginx
    build:
      context: ./Nginx
      dockerfile: Dockerfile.prod
      args:
        - "VERSION=${Nginx_VERSION}"
    ports: 
      - "${HOST_OPEN_PORT}:${Nginx_PORT}"
    depends_on:
      - django
    volumes:
      - static_vol:/home/app/web/static

volumes:
  # shared volume between django & Nginx,so that Nginx can serve static file,lessing the load on the server
  static_vol:
  db_data:

Nginx 配置:

# name the upstream server,on which Nginx acts as a reverse proxy
upstream myproject {
    server django:8000;     # must be the name of the django service on docKer's virtual network
}

server {

    listen 80;
    location / {
        proxy_pass http://myproject;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        client_max_body_size 20M;
    }

    location /static/ {
        alias /home/app/web/static/;
    }


}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...