At the moment I have the following configuration, in which I get an error:
Failed to load resource: the server responded with a status of 404 (Not Found)
As I understand it, I entered the path incorrectly and nginx cannot give the build.js file, which is missing from this path. How can I properly configure nginx so that it serves this file.
Config nginx:
upstream music {
server web:8000;
}
server {
listen 80;
server_name ***;
access_log /var/log/nginx/logs.log;
location /vue-frontend/ {
root /app/;
}
location / {
proxy_pass http://music;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /staticfiles/ {
root /home/app/web;
}
location /media/ {
root /home/app/web;
}
}
The entire vue js project lies in the django project folder. Vue is embedded in the django template along the templates / base.html path
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
{% load render_bundle from webpack_loader %}
</head>
<body>
<div class="main_content">
<div id="app"></div>
{% render_bundle 'main' %}
</div>
</body>
</html>
file docker-compose.prod.yml:
version: "3.8"
services:
web:
build:
context: ./
dockerfile: Dockerfile.prod
command: gunicorn music.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media
expose:
- 8000
env_file:
- ./.env.prod
depends_on:
- db
vue:
build:
context: ./vue-frontend
dockerfile: Dockerfile.prod
volumes:
- vue_dist:/app/dist
depends_on:
- web
db:
image: postgres:12.0
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.prod.db
nginx:
build: ./nginx
ports:
- 80:80
volumes:
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media
- vue_dist:/app/dist
depends_on:
- web
- vue
volumes:
postgres_data:
static_volume:
media_volume:
vue_dist:
In my index.html(base.html) layout
...
<body>
<div class="main_content">
<div id="app"></div>
<script type="text/javascript" src="http://*.*.*.*/vue-frontend/dist/build.js" ></script>
</div>
</body>
...
location /vue-frontend/block, on line 2 after thealias?try_files $uri $uri/ /index.html;