我正在尝试将自己制作的初稿提交到我自己运行CentOS 7的本地生产服务器中。
到目前为止,到目前为止,我一直在开发模式下使用proxy.config.json
在Django和Angular之间进行绑定。
{
"/api": {
"target": "example.me",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
当我想投入生产时,我未能将容器前端与后端绑定。这些是我所做的设置
FROM python:3.8
# USER app
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
FROM node:12.16.2 AS build
LABEL version="0.0.1"
WORKDIR /app
COPY ["package.json","npm-shrinkwrap.json*","./"]
RUN npm install -g @angular/cli
RUN npm install --silent
COPY . .
RUN ng build --prod
FROM nginx:latest
RUN rm -rf /usr/share/nginx/html/*
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist/frontend /usr/share/nginx/html
EXPOSE "3108"
version: '3'
services:
db:
image: postgres
environment:
- POSTGRES_DB=database_name
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
networks:
- app
backend:
build: .
command: gunicorn --bind 0.0.0.0:80 myproject.wsgi
volumes:
- .:/code
ports:
- "80:80"
networks:
- app
depends_on:
- db
frontend:
build:
context: ../frontend
dockerfile: Dockerfile
command: nginx -g "daemon off;"
ports:
- "3108:3108"
networks:
- app
depends_on:
- backend
networks:
app:
server {
listen 3108;
server_name example.me;
root /usr/share/nginx/html;
location / {
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
我试图通过添加来模仿角度代理 在this post谈到docker时遵循了一个答案
location /api {
proxy_pass example.me;
}
这是由于后端返回Error 403
然后,我将BaseEndPoint更改为直接从服务器请求,并将corsheaders
添加到django中并开始获取401 Error
。
export const environment = {
production: true,
ConfigApi: {
BaseEndPoint: 'example.me',
LoginEndPoint: '/api/account/login/',
RegisterEndPoint: '/api/account/registration/',
MembersList: '/api/membres_list/',
Meeting: '/api/meeting/create_list/',
TaskList: '/api/task_list/create/',
}
};
我无法指出问题或其来源;我应该指出,邮递员对后端的请求工作正常。
后端不断用403
或401
拒绝前端请求,我不知道为什么